Pre Publish Checks#

This example plugin runs custom checks before a publish and before each export.
If the checks are not passed, the publish/export will be canceled.

See the section for Single File Plugins on how to load this example.

# PrePublishChecks.py

name = "PrePublishChecks"
classname = "PrePublishChecks"


class PrePublishChecks:
    def __init__(self, core):
        self.core = core
        self.version = "v1.0.0"

        # register prePublish and preExport callbacks
        self.core.registerCallback("prePublish", self.prePublish, plugin=self)
        self.core.registerCallback("preExport", self.preExport, plugin=self)

    # this function will be called once before every publish
    def prePublish(self, origin):
        # run pre publish checks here
        passed = False

        if not passed:
            self.core.popup("Pre-Publish checks not passed. Please fix your scene.")

        return {"cancel": not passed}

    # this function will be called before the execution of every export state
    def preExport(self, **kwargs):
        # run pre export checks here
        passed = kwargs["state"].getOutputType() == ".abc"  # True if the Outputtype of the export state is set to .abc

        if not passed:
            self.core.popup("Pre-Export checks not passed. Please fix your scene.")

        return {"cancel": not passed}