How can I add a toggle to the publisher in Houdini?

In my addon, the paths to the plugins are set up in addon.py, and I created a class there in validate_range.py , but the toggle doesn’t appear.
client/
└── my_addon_houdini/
├── plugins/
│ └── publish/
│ ├── validate_range.py
└── addon.py


my code

from ayon_core.pipeline.publish import (
    RepairAction,
    ValidateContentsOrder,
    OptionalPyblishPluginMixin
)
from ayon_houdini.api import plugin

class ValidateCorrectCurrentFrameRange(plugin.HoudiniInstancePlugin, OptionalPyblishPluginMixin):
    print("VALIdATE")
    order = ValidateContentsOrder
    label = "Validate Frame in Context"
    optional = True
    actions = [RepairAction]

    def process(self, instance):
        self.log.info("aAAAAAAAAAAAAAAA")
        if not self.is_active(instance.data):
            return

        attr_values = self.get_attr_values_from_data(instance.data)
        if not attr_values and not instance.data.get("instance_node"):
            return

If you want it under the Context make sure that your plug-in is a ContextPlugin and not an InstancePlugin.

Or inherit from AYONPyblishPluginMixin instead of OptionalPyblishPluginMixin and implement get_attr_defs_for_context, but then you have to implement custom implementation of is_active because the value would not be stored on instance but on context.

Hi, thanks for the advice, but it didn’t work. I added Context to the class, but unfortunately the toggle still didn’t appear.


I also tried the suggestion above, but it didn’t help. Could you recommend a Houdini addon that does the same thing (adds a toggle to the context) as an example?

You’ve combined the 2 approaches, choose one. If it can be context plugin (not instance specific) then just use HoudiniContextPlugin and OptionalPyblishPluginMixin as you did.

Ignore this if it can be context plugin.

Class AYONPyblishPluginMixin is in ayon_core.pipeline.publish but you’re importing it from ayon_houdini.api.plugin for some reason? The get_attr_defs_for_context should be a classmethod on the plugin, not a function.

class ValidateCorrectCurrentFrameRange(
    plugin.HoudiniInstnacePlugin,
    AYONPyblishPluginMixin
):
    ...defs...

    def process(self, instance):
        if not self.is_active(instance.context.data):
            return

        ...rest of logic...

    @classmethod
    def get_attr_defs_for_context(cls):
        return [
            BoolDef("active", default=True)
        ]

2 Likes