From 06b55cbcaaf2b324ab83a551ab61167722956c24 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Mon, 25 May 2020 11:38:58 +0100 Subject: [PATCH] Import templates. --- .../{template.py => create_template.py} | 0 pype/plugins/harmony/load/load_template.py | 48 +++++++++++++++++++ 2 files changed, 48 insertions(+) rename pype/plugins/harmony/create/{template.py => create_template.py} (100%) create mode 100644 pype/plugins/harmony/load/load_template.py diff --git a/pype/plugins/harmony/create/template.py b/pype/plugins/harmony/create/create_template.py similarity index 100% rename from pype/plugins/harmony/create/template.py rename to pype/plugins/harmony/create/create_template.py diff --git a/pype/plugins/harmony/load/load_template.py b/pype/plugins/harmony/load/load_template.py new file mode 100644 index 0000000000..711c43a913 --- /dev/null +++ b/pype/plugins/harmony/load/load_template.py @@ -0,0 +1,48 @@ +import tempfile +import zipfile +import os +import shutil + +from avalon import api, harmony + + +class ImportTemplateLoader(api.Loader): + """Import templates.""" + + families = ["template"] + representations = ["*"] + label = "Import Template" + + def load(self, context, name=None, namespace=None, data=None): + 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)