Publish2 validate a single task

Cheerio folks,
I’m trying to impplement a way of validating only a single task from the Publish2 app inside of Maya.

My initial try was to create a custom ui for that task with one button. I pointed the clicked callback of that button to the validate function of the task. This works perfectly fine however it does not update the UI of the PublishTreeWidget as it would when executing a full validation process.

I’m currently trying to execute the PublishManager's validate funnction with a custom generator yielding only the desired task. However, I don’t quite get it to update the UI :confused:

Any ideas on how to achieve this?

3 Likes

I think I’m on the right track thanks to this post:

I’ll keep you posted and share some code once I have something working :slight_smile:

4 Likes

Glad you found the info you were after @tonyd! Looking forward to seeing the working code. :slight_smile: Best of luck!

2 Likes

Ok so here’s what I got…
The idea is to add a custom GUI with just a single button “Validate Me” that connects to single_validation on clicked.

def single_validation(self):
    # create a new publish manager instance
    manager = PublishApp.create_publish_manager()  # sgtk.platform.current_engine().apps.get("tk-multi-publish2")
    manager.validate(task_generator=self.single_task_generator())

def single_task_generator(self):
    is_standalone = True  # indicates that no Publish phase will follow
    for ui_item in self.__single_task_validate_generator():
        try:
            # yield each child item to be acted on by the publish api
            if isinstance(ui_item, TreeNodeTask):
                (is_successful, error) = yield ui_item.task
                error_msg = str(error)

            # all other nodes are UI-only and can handle their own validation
            else:
                is_successful = ui_item.validate(is_standalone)
                error_msg = "Unknown validation error!"
        except Exception as e:
            ui_item.set_status(ui_item.STATUS_VALIDATION_ERROR, str(e))
            raise
        else:
            if is_successful:
                if is_standalone:
                    ui_item.set_status(ui_item.STATUS_VALIDATION_STANDALONE)
                else:
                    ui_item.set_status(ui_item.STATUS_VALIDATION)
            else:
                ui_item.set_status(ui_item.STATUS_VALIDATION_ERROR, error_msg)

def __single_task_validate_generator(self):
    for ui_item in self.__tree_ui_items():
        # if self._stop_processing_flagged:
        #     # jump out of the iteration
        #     break

        if not ui_item.checked:
            continue

        # self._progress_handler.push(
        #     "%s: %s" % (stage_name, ui_item,),
        #     ui_item.icon,
        #     ui_item.get_publish_instance(),
        # )

        try:
            yield ui_item
        except Exception as e:
            self.logger.info(e)
        # finally:
        #     self._progress_handler.increment_progress()
        #     self._progress_handler.pop()

This is basically just copy/pasted from tk-multi-publish2 --> dialog.py --> _validate_task_generator(), _task_generator(), _get_tree_items().

To be able to acces the Publisher’s UI I simply added self.widget = widget to the DCC’s engine.py show_dialog method just before it returns.
I don’t know if this has any downsides since this was considered as not that easy in the post i referenced earlier. Maybe someone of you folks knows a better way of accessing app ui’s from hooks?

2 Likes

Hi Tony

We don’t have anyway to access the main UI from within the hooks, at least not without modifying the app its self or going via hacky private variables.
The only part of the UI that is intended to be customizable is the plugin panel.

What your trying to do is a cool idea though!
Best
Phil

1 Like