From 3bbd29dafc262d8984e83e4cf638e6a8b8a033e2 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Sun, 6 Oct 2024 15:14:22 +0200 Subject: [PATCH 1/3] Show/hide attributes per instance based on status of other toggles --- .../extract_usd_layer_contributions.py | 73 ++++++++++++++++--- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py b/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py index acdc5276f7..a67c6ec702 100644 --- a/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py +++ b/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py @@ -458,7 +458,22 @@ def get_or_create_instance(self, return new_instance @classmethod - def get_attribute_defs(cls): + def get_attr_defs_for_instance(cls, create_context, instance): + # Filtering of instance, if needed, can be customized + if not cls.instance_matches_plugin_families(instance): + return [] + + # Attributes logic + disabled = False + publish_attributes = instance["publish_attributes"].get( + cls.__name__, {}) + + enabled = publish_attributes.get("contribution_enabled", True) + variant_enabled = enabled and publish_attributes.get( + "contribution_apply_as_variant", True) + + disabled = not enabled + variant_disabled = not variant_enabled return [ UISeparatorDef("usd_container_settings1"), @@ -484,7 +499,8 @@ def get_attribute_defs(cls): "the contribution itself will be added to the " "department layer." ), - default="usdAsset"), + default="usdAsset", + hidden=disabled), EnumDef("contribution_target_product_init", label="Initialize as", tooltip=( @@ -495,7 +511,8 @@ def get_attribute_defs(cls): "setting will do nothing." ), items=["asset", "shot"], - default="asset"), + default="asset", + hidden=disabled), # Asset layer, e.g. model.usd, look.usd, rig.usd EnumDef("contribution_layer", @@ -507,7 +524,8 @@ def get_attribute_defs(cls): "the list) will contribute as a stronger opinion." ), items=list(cls.contribution_layers.keys()), - default="model"), + default="model", + hidden=disabled), BoolDef("contribution_apply_as_variant", label="Add as variant", tooltip=( @@ -518,13 +536,16 @@ def get_attribute_defs(cls): "appended to as a sublayer to the department layer " "instead." ), - default=True), + default=True, + hidden=disabled), TextDef("contribution_variant_set_name", label="Variant Set Name", - default="{layer}"), + default="{layer}", + hidden=variant_disabled), TextDef("contribution_variant", label="Variant Name", - default="{variant}"), + default="{variant}", + hidden=variant_disabled), BoolDef("contribution_variant_is_default", label="Set as default variant selection", tooltip=( @@ -535,10 +556,41 @@ def get_attribute_defs(cls): "The behavior is unpredictable if multiple instances " "for the same variant set have this enabled." ), - default=False), + default=False, + hidden=variant_disabled), UISeparatorDef("usd_container_settings3"), ] + @classmethod + def register_create_context_callbacks(cls, create_context): + create_context.add_value_changed_callback(cls.on_values_changed) + + @classmethod + def on_values_changed(cls, event): + """Update instance attribute definitions on attribute changes.""" + + # Update attributes if any of the following plug-in attributes + # change: + keys = ["contribution_enabled", "contribution_apply_as_variant"] + + for instance_change in event["changes"]: + instance = instance_change["instance"] + if not cls.instance_matches_plugin_families(instance): + continue + value_changes = instance_change["changes"] + plugin_attribute_changes = ( + value_changes.get("publish_attributes", {}) + .get(cls.__name__, {})) + + if not any(key in plugin_attribute_changes for key in keys): + continue + + # Update the attribute definitions + new_attrs = cls.get_attr_defs_for_instance( + event["create_context"], instance + ) + instance.set_publish_plugin_attr_defs(cls.__name__, new_attrs) + class CollectUSDLayerContributionsHoudiniLook(CollectUSDLayerContributions): """ @@ -551,9 +603,8 @@ class CollectUSDLayerContributionsHoudiniLook(CollectUSDLayerContributions): label = CollectUSDLayerContributions.label + " (Look)" @classmethod - def get_attribute_defs(cls): - defs = super(CollectUSDLayerContributionsHoudiniLook, - cls).get_attribute_defs() + def get_attr_defs_for_instance(cls, create_context, instance): + defs = super().get_attr_defs_for_instance(create_context, instance) # Update default for department layer to look layer_def = next(d for d in defs if d.key == "contribution_layer") From 92e43fc45b81a9305589be85871011cf3236012c Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 23 Oct 2024 23:44:24 +0200 Subject: [PATCH 2/3] Fix variable names + simplify logic --- .../extract_usd_layer_contributions.py | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py b/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py index a67c6ec702..0ffce8b643 100644 --- a/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py +++ b/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py @@ -464,17 +464,13 @@ def get_attr_defs_for_instance(cls, create_context, instance): return [] # Attributes logic - disabled = False publish_attributes = instance["publish_attributes"].get( cls.__name__, {}) - enabled = publish_attributes.get("contribution_enabled", True) - variant_enabled = enabled and publish_attributes.get( + visible = publish_attributes.get("contribution_enabled", True) + variant_visible = visible and publish_attributes.get( "contribution_apply_as_variant", True) - disabled = not enabled - variant_disabled = not variant_enabled - return [ UISeparatorDef("usd_container_settings1"), UILabelDef(label="USD Contribution"), @@ -500,7 +496,7 @@ def get_attr_defs_for_instance(cls, create_context, instance): "department layer." ), default="usdAsset", - hidden=disabled), + visible=visible), EnumDef("contribution_target_product_init", label="Initialize as", tooltip=( @@ -512,7 +508,7 @@ def get_attr_defs_for_instance(cls, create_context, instance): ), items=["asset", "shot"], default="asset", - hidden=disabled), + visible=visible), # Asset layer, e.g. model.usd, look.usd, rig.usd EnumDef("contribution_layer", @@ -525,7 +521,7 @@ def get_attr_defs_for_instance(cls, create_context, instance): ), items=list(cls.contribution_layers.keys()), default="model", - hidden=disabled), + visible=visible), BoolDef("contribution_apply_as_variant", label="Add as variant", tooltip=( @@ -537,15 +533,15 @@ def get_attr_defs_for_instance(cls, create_context, instance): "instead." ), default=True, - hidden=disabled), + visible=visible), TextDef("contribution_variant_set_name", label="Variant Set Name", default="{layer}", - hidden=variant_disabled), + visible=variant_visible), TextDef("contribution_variant", label="Variant Name", default="{variant}", - hidden=variant_disabled), + visible=variant_visible), BoolDef("contribution_variant_is_default", label="Set as default variant selection", tooltip=( @@ -557,7 +553,7 @@ def get_attr_defs_for_instance(cls, create_context, instance): "for the same variant set have this enabled." ), default=False, - hidden=variant_disabled), + visible=variant_visible), UISeparatorDef("usd_container_settings3"), ] From 11bb657d35921c42759339937ee8b82230235e98 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 24 Oct 2024 22:10:25 +0200 Subject: [PATCH 3/3] Do not try to continue with logic if the instance isn't valid for the plug-in anyway --- .../plugins/publish/extract_usd_layer_contributions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py b/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py index 0ffce8b643..180cb8bbf1 100644 --- a/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py +++ b/client/ayon_core/plugins/publish/extract_usd_layer_contributions.py @@ -600,6 +600,10 @@ class CollectUSDLayerContributionsHoudiniLook(CollectUSDLayerContributions): @classmethod def get_attr_defs_for_instance(cls, create_context, instance): + # Filtering of instance, if needed, can be customized + if not cls.instance_matches_plugin_families(instance): + return [] + defs = super().get_attr_defs_for_instance(create_context, instance) # Update default for department layer to look