Fix publishing workfile

- Unified template export across workfile and templates.
- Fix scene saving per instance.
- Cleanup template loader.
This commit is contained in:
Toke Stuart Jepsen 2020-06-16 12:59:42 +01:00
parent 9fee13a58a
commit c69bf58d3b
5 changed files with 70 additions and 77 deletions

View file

@ -84,6 +84,51 @@ def ensure_scene_settings():
harmony.send({"function": func, "args": [valid_settings]})
def export_template(backdrops, nodes, filepath):
func = """function func(args)
{
// 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": [
backdrops,
nodes,
os.path.basename(filepath),
os.path.dirname(filepath)
]
})
def install():
print("Installing Pype config...")

View file

@ -14,18 +14,6 @@ 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"])
@ -33,19 +21,6 @@ class ImportTemplateLoader(api.Loader):
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(template_path)
func = """function func(args)
{
var template_path = args[0];
var drag_object = copyPaste.copyFromTemplate(
template_path, 0, 0, copyPaste.getCurrentCreateOptions()
);
copyPaste.pasteNewNodes(
drag_object, "", copyPaste.getCurrentPasteOptions()
);
}
func
"""
func = """function func(args)
{
var template_path = args[0];

View file

@ -9,5 +9,5 @@ class ExtractSaveScene(pyblish.api.ContextPlugin):
order = pyblish.api.ExtractorOrder - 0.49
hosts = ["harmony"]
def process(self, instance):
def process(self, context):
harmony.save_scene()

View file

@ -2,7 +2,8 @@ import os
import shutil
import pype.api
from avalon import harmony
import avalon.harmony
import pype.hosts.harmony
class ExtractTemplate(pype.api.Extractor):
@ -14,6 +15,7 @@ class ExtractTemplate(pype.api.Extractor):
def process(self, instance):
staging_dir = self.staging_dir(instance)
filepath = os.path.join(staging_dir, "{}.tpl".format(instance.name))
self.log.info("Outputting template to {}".format(staging_dir))
@ -28,7 +30,7 @@ class ExtractTemplate(pype.api.Extractor):
unique_backdrops = [backdrops[x] for x in set(backdrops.keys())]
# Get non-connected nodes within backdrops.
all_nodes = harmony.send(
all_nodes = avalon.harmony.send(
{"function": "node.subNodes", "args": ["Top"]}
)["result"]
for node in [x for x in all_nodes if x not in dependencies]:
@ -43,48 +45,9 @@ class ExtractTemplate(pype.api.Extractor):
dependencies.remove(instance[0])
# Export template.
func = """function func(args)
{
// 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
]
})
pype.hosts.harmony.export_template(
unique_backdrops, dependencies, filepath
)
# Prep representation.
os.chdir(staging_dir)
@ -131,7 +94,7 @@ class ExtractTemplate(pype.api.Extractor):
}
func
"""
return harmony.send(
return avalon.harmony.send(
{"function": func, "args": [node]}
)["result"]
@ -150,7 +113,7 @@ class ExtractTemplate(pype.api.Extractor):
func
"""
current_dependencies = harmony.send(
current_dependencies = avalon.harmony.send(
{"function": func, "args": [node]}
)["result"]

View file

@ -2,6 +2,8 @@ import os
import shutil
import pype.api
import avalon.harmony
import pype.hosts.harmony
class ExtractWorkfile(pype.api.Extractor):
@ -12,17 +14,25 @@ class ExtractWorkfile(pype.api.Extractor):
families = ["workfile"]
def process(self, instance):
file_path = instance.context.data["currentFile"]
# Export template.
backdrops = avalon.harmony.send(
{"function": "Backdrop.backdrops", "args": ["Top"]}
)["result"]
nodes = avalon.harmony.send(
{"function": "node.subNodes", "args": ["Top"]}
)["result"]
staging_dir = self.staging_dir(instance)
filepath = os.path.join(staging_dir, "{}.tpl".format(instance.name))
pype.hosts.harmony.export_template(backdrops, nodes, filepath)
# Prep representation.
os.chdir(staging_dir)
shutil.make_archive(
instance.name,
"{}".format(instance.name),
"zip",
os.path.dirname(file_path)
os.path.join(staging_dir, "{}.tpl".format(instance.name))
)
zip_path = os.path.join(staging_dir, instance.name + ".zip")
self.log.info(f"Output zip file: {zip_path}")
representation = {
"name": "tpl",