mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #250 from tokejepsen/2.x/feature/harmony_load_template_workfile
Loader for templates and workfiles
This commit is contained in:
commit
eb9aa7c051
1 changed files with 69 additions and 0 deletions
69
pype/plugins/harmony/load/load_template_workfile.py
Normal file
69
pype/plugins/harmony/load/load_template_workfile.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import tempfile
|
||||
import zipfile
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from avalon import api, harmony
|
||||
|
||||
|
||||
class ImportTemplateLoader(api.Loader):
|
||||
"""Import templates."""
|
||||
|
||||
families = ["harmony.template"]
|
||||
representations = ["*"]
|
||||
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")
|
||||
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];
|
||||
var drag_object = copyPaste.pasteTemplateIntoGroup(
|
||||
template_path, "Top", 1
|
||||
);
|
||||
}
|
||||
func
|
||||
"""
|
||||
|
||||
harmony.send({"function": func, "args": [template_path]})
|
||||
|
||||
shutil.rmtree(temp_dir)
|
||||
|
||||
|
||||
class ImportWorkfileLoader(ImportTemplateLoader):
|
||||
"""Import workfiles."""
|
||||
|
||||
families = ["workfile"]
|
||||
representations = ["*"]
|
||||
label = "Import Workfile"
|
||||
Loading…
Add table
Add a link
Reference in a new issue