From 48cee11492602296c505ba05aa5e916424be51c3 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 16 Mar 2018 13:02:13 +0100 Subject: [PATCH] Implement on instanceToggled callback in Fusion install to toggle saver passthrough for Pyblish interface --- colorbleed/fusion/__init__.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/colorbleed/fusion/__init__.py b/colorbleed/fusion/__init__.py index 36270980bf..86ee04a71a 100644 --- a/colorbleed/fusion/__init__.py +++ b/colorbleed/fusion/__init__.py @@ -18,9 +18,39 @@ def install(): avalon.register_plugin_path(avalon.Loader, LOAD_PATH) avalon.register_plugin_path(avalon.Creator, CREATE_PATH) + pyblish.register_callback("instanceToggled", on_pyblish_instance_toggled) + def uninstall(): print("Deregistering Fusion plug-ins..") pyblish.deregister_plugin_path(PUBLISH_PATH) avalon.deregister_plugin_path(avalon.Loader, LOAD_PATH) avalon.deregister_plugin_path(avalon.Creator, CREATE_PATH) + + pyblish.deregister_callback("instanceToggled", on_pyblish_instance_toggled) + + +def on_pyblish_instance_toggled(instance, new_value, old_value): + """Toggle saver tool passthrough states on instance toggles.""" + + from avalon.fusion import comp_lock_and_undo_chunk + + comp = instance.context.data.get("currentComp") + if not comp: + return + + savers = [tool for tool in instance if + getattr(tool, "ID", None) == "Saver"] + if not savers: + return + + # Whether instances should be passthrough based on new value + passthrough = not new_value + with comp_lock_and_undo_chunk(comp, + undo_queue_name="Change instance " + "active state"): + for tool in savers: + attrs = tool.GetAttrs() + current = attrs["TOOLB_PassThrough"] + if current != passthrough: + tool.SetAttrs({"TOOLB_PassThrough": passthrough})