Publish Plugin default check state

A question I have seen asked in support a few times is how can you have a publish plugin or item unchecked by default in the publish2 app?

Plugins

The default check state of a plugin is set in the accept method of the plugin:

You can take over the publish plugin hook, inherit from the base, and implement just the accept method:

Create a publish hook in your .../config/hooks/tk-multi-publish/upload_version.py

import sgtk

HookBaseClass = sgtk.get_hook_baseclass()

class UploadVersionPlugin(HookBaseClass):
    def accept(self, settings, item):
        # get the base settings
        settings = super(UploadVersionPlugin, self).accept(settings, item)
        # set the default checked state
        settings["checked"] = False
        return settings

And then in your .../config/env/includes/settings/tk-multi-publish2.yml you would set the plugin hook inheritance to be:

hook: "{self}/upload_version.py:{config}/tk-multi-publish2/upload_version.py"

Items

For a collected item, you need to set the PublishItem.checked at collection time.
Here is an example where I am by default setting the item collected by the standalone publisher to unchecked

import sgtk

HookBaseClass = sgtk.get_hook_baseclass()

class BasicSceneCollector(HookBaseClass):

    def process_file(self, settings, parent_item, path):
        item = super(BasicSceneCollector, self).process_file(settings, parent_item, path)
        item.checked = False
        return item

And the setting would then look like this, asuming I saved my hook to .../config/hooks/tk-multi-publish2/collector.py

collector: "{self}/collector.py:{config}/tk-multi-publish2/collector.py"
7 Likes

Hi @philip.scadding

Thanks for this post. It would be really useful to know how you would go about configuring the plugin as required. As in, its checkbox is checked by default and cannot be unchecked.

Any insight would be appreciated, thanks!

1 Like

Fair question. The enabled property on the plugin should allow you to achieve that behaviour I think.
The publish item has a similar enabled property but the docs seem to suggest it has a different behaviour, I’ve not tested to see if this is the case.

Or was it that you’re not sure how to actually go about making the change?

1 Like

@philip.scadding yeah, I’m not sure where exactly I should make the change in my custom hook, setting its enabled property doesn’t seem to work. Could you please demonstrate how you’d do this in your UploadVersionPlugin hook, for example?

1 Like

Just figured it out, it’s set in the accept method:

def accept(self, settings, item):
    return {'accepted': True, 'enabled': False}

Thanks for the help @philip.scadding

3 Likes

Using the accept method works, but I can’t get to work the item.checked = False in collector only. It is still checked in UI…

1 Like

item._expanded = False works but not item.checked = False in collector.
I am looking for a solution that item should be checked and disabled so that user should not disable the item during publish.