From 9d9ef80f1c5b4c5d5977417f1addede9bfb7c989 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Thu, 28 May 2020 17:12:53 +0100 Subject: [PATCH 1/2] Publish backdrops with templates. - other nodes within the bounding box of the backdrops are published as well, cause non-connected notes can be used to communicate to the end user. - not publishing templates to ftrack. --- pype/plugins/harmony/load/load_template.py | 13 ++++ .../harmony/publish/collect_instances.py | 3 +- .../harmony/publish/extract_template.py | 73 +++++++++++++++++-- 3 files changed, 79 insertions(+), 10 deletions(-) diff --git a/pype/plugins/harmony/load/load_template.py b/pype/plugins/harmony/load/load_template.py index 0bc9706407..53e0ff1f07 100644 --- a/pype/plugins/harmony/load/load_template.py +++ b/pype/plugins/harmony/load/load_template.py @@ -14,6 +14,19 @@ class ImportTemplateLoader(api.Loader): label = "Import Template" def load(self, context, name=None, namespace=None, data=None): + # Make backdrops from metadata. + backdrops = context["representation"]["data"].get("backdrops", []) + + func = """function func(args) + { + Backdrop.addBackdrop("Top", args[0]); + } + func + """ + for backdrop in backdrops: + harmony.send({"function": func, "args": [backdrop]}) + + # Import template. temp_dir = tempfile.mkdtemp() zip_file = api.get_representation_path(context["representation"]) template_path = os.path.join(temp_dir, "temp.tpl") diff --git a/pype/plugins/harmony/publish/collect_instances.py b/pype/plugins/harmony/publish/collect_instances.py index 9626cb3693..8769ac80cc 100644 --- a/pype/plugins/harmony/publish/collect_instances.py +++ b/pype/plugins/harmony/publish/collect_instances.py @@ -18,7 +18,7 @@ class CollectInstances(pyblish.api.ContextPlugin): order = pyblish.api.CollectorOrder hosts = ["harmony"] families_mapping = { - "render": ["imagesequence", "review"], + "render": ["imagesequence", "review", "ftrack"], "harmony.template": [] } @@ -45,7 +45,6 @@ class CollectInstances(pyblish.api.ContextPlugin): {"function": "node.getEnable", "args": [node]} )["result"] instance.data["families"] = self.families_mapping[data["family"]] - instance.data["families"].append("ftrack") # Produce diagnostic message for any graphical # user interface interested in visualising it. diff --git a/pype/plugins/harmony/publish/extract_template.py b/pype/plugins/harmony/publish/extract_template.py index 78184217dc..96159ac8db 100644 --- a/pype/plugins/harmony/publish/extract_template.py +++ b/pype/plugins/harmony/publish/extract_template.py @@ -7,6 +7,7 @@ from avalon import harmony class ExtractTemplate(pype.api.Extractor): """Extract the connected nodes to the composite instance.""" + label = "Extract Template" hosts = ["harmony"] families = ["harmony.template"] @@ -14,10 +15,32 @@ class ExtractTemplate(pype.api.Extractor): def process(self, instance): staging_dir = self.staging_dir(instance) - self.log.info("Outputting template to %s" % staging_dir) + self.log.info("Outputting template to {}".format(staging_dir)) - self.dependencies = [] - self.get_dependencies(instance[0]) + dependencies = [] + self.get_dependencies(instance[0], dependencies) + + # Get backdrops. + backdrops = {} + for dependency in dependencies: + for backdrop in self.get_backdrops(dependency): + backdrops[backdrop["title"]["text"]] = backdrop + unique_backdrops = [backdrops[x] for x in set(backdrops.keys())] + + # Get non-connected nodes within backdrops. + all_nodes = harmony.send( + {"function": "node.subNodes", "args": ["Top"]} + )["result"] + for node in [x for x in all_nodes if x not in dependencies]: + within_unique_backdrops = bool( + [x for x in self.get_backdrops(node) if x in unique_backdrops] + ) + if within_unique_backdrops: + dependencies.append(node) + + # Make sure we dont export the instance node. + if instance[0] in dependencies: + dependencies.remove(instance[0]) func = """function func(args) { @@ -30,7 +53,7 @@ class ExtractTemplate(pype.api.Extractor): } func """ - harmony.send({"function": func, "args": [self.dependencies]}) + harmony.send({"function": func, "args": [dependencies]}) func = """function func(args) { copyPaste.createTemplateFromSelection(args[0], args[1]); @@ -56,10 +79,44 @@ class ExtractTemplate(pype.api.Extractor): "ext": "zip", "files": "{}.zip".format(instance.name), "stagingDir": staging_dir, + "data": {"backdrops": unique_backdrops} } instance.data["representations"] = [representation] - def get_dependencies(self, node): + def get_backdrops(self, node): + func = """function func(probe_node) + { + var backdrops = Backdrop.backdrops("Top"); + var valid_backdrops = []; + for(var i=0; i Date: Fri, 29 May 2020 12:29:52 +0100 Subject: [PATCH 2/2] Exporting the template files with backdrop as well. --- .../harmony/publish/extract_template.py | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/pype/plugins/harmony/publish/extract_template.py b/pype/plugins/harmony/publish/extract_template.py index 96159ac8db..f7a5e34e67 100644 --- a/pype/plugins/harmony/publish/extract_template.py +++ b/pype/plugins/harmony/publish/extract_template.py @@ -42,31 +42,51 @@ class ExtractTemplate(pype.api.Extractor): if instance[0] in dependencies: dependencies.remove(instance[0]) + # Export template. func = """function func(args) { - var nodes = args[0]; - selection.clearSelection(); - for (var i = 0 ; i < nodes.length; i++) - { - selection.addNodeToSelection(nodes[i]); - } - } - func - """ - harmony.send({"function": func, "args": [dependencies]}) - func = """function func(args) - { - copyPaste.createTemplateFromSelection(args[0], args[1]); - } - func - """ - harmony.send( - { - "function": func, - "args": ["{}.tpl".format(instance.name), staging_dir] - } - ) + // Add an extra node just so a new group can be created. + var temp_node = node.add("Top", "temp_note", "NOTE", 0, 0, 0); + var template_group = node.createGroup(temp_node, "temp_group"); + node.deleteNode( template_group + "/temp_note" ); + // This will make Node View to focus on the new group. + selection.clearSelection(); + selection.addNodeToSelection(template_group); + Action.perform("onActionEnterGroup()", "Node View"); + + // Recreate backdrops in group. + for (var i = 0 ; i < args[0].length; i++) + { + Backdrop.addBackdrop(template_group, args[0][i]); + }; + + // Copy-paste the selected nodes into the new group. + var drag_object = copyPaste.copy(args[1], 1, frame.numberOf, ""); + copyPaste.pasteNewNodes(drag_object, template_group, ""); + + // Select all nodes within group and export as template. + Action.perform( "selectAll()", "Node View" ); + copyPaste.createTemplateFromSelection(args[2], args[3]); + + // Unfocus the group in Node view, delete all nodes and backdrops + // created during the process. + Action.perform("onActionUpToParent()", "Node View"); + node.deleteNode(template_group, true, true); + } + func + """ + harmony.send({ + "function": func, + "args": [ + unique_backdrops, + dependencies, + "{}.tpl".format(instance.name), + staging_dir + ] + }) + + # Prep representation. os.chdir(staging_dir) shutil.make_archive( "{}".format(instance.name), @@ -78,8 +98,7 @@ class ExtractTemplate(pype.api.Extractor): "name": "tpl", "ext": "zip", "files": "{}.zip".format(instance.name), - "stagingDir": staging_dir, - "data": {"backdrops": unique_backdrops} + "stagingDir": staging_dir } instance.data["representations"] = [representation]