From 8ae92351a7e3e1758cca4a62e4170749ed93a914 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 16 Sep 2022 21:27:00 +0800 Subject: [PATCH 01/29] Import Reference during Publish --- openpype/hosts/maya/plugins/create/create_look.py | 3 +++ openpype/hosts/maya/plugins/publish/extract_look.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/openpype/hosts/maya/plugins/create/create_look.py b/openpype/hosts/maya/plugins/create/create_look.py index 44e439fe1f..cecdf9f54d 100644 --- a/openpype/hosts/maya/plugins/create/create_look.py +++ b/openpype/hosts/maya/plugins/create/create_look.py @@ -21,6 +21,9 @@ class CreateLook(plugin.Creator): # Whether to automatically convert the textures to .tx upon publish. self.data["maketx"] = self.make_tx + # Enable users to import reference + self.data["importReference"] = False + # Enable users to force a copy. # - on Windows is "forceCopy" always changed to `True` because of # windows implementation of hardlinks diff --git a/openpype/hosts/maya/plugins/publish/extract_look.py b/openpype/hosts/maya/plugins/publish/extract_look.py index 91b0da75c6..845af0d32d 100644 --- a/openpype/hosts/maya/plugins/publish/extract_look.py +++ b/openpype/hosts/maya/plugins/publish/extract_look.py @@ -255,6 +255,14 @@ class ExtractLook(publish.Extractor): hashes = results["fileHashes"] remap = results["attrRemap"] + # Import Reference if the option is enabled + ref_import = instance.data.get("importReference", True) + if ref_import: + reference_node = cmds.ls(type="reference") + for r in reference_node: + rFile = cmds.referenceQuery(r, f=True) + cmds.file(rFile, importReference=True) + # Extract in correct render layer layer = instance.data.get("renderlayer", "defaultRenderLayer") with lib.renderlayer(layer): From 25279d276d8ef1035aea327c67b49a44ab29d647 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 17:59:39 +0800 Subject: [PATCH 02/29] Import Reference during Publish --- .../hosts/maya/plugins/create/create_look.py | 3 - .../publish/extract_import_reference.py | 122 ++++++++++++++++++ .../maya/plugins/publish/extract_look.py | 8 -- .../defaults/project_settings/maya.json | 3 + .../schemas/schema_maya_publish.json | 16 ++- 5 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 openpype/hosts/maya/plugins/publish/extract_import_reference.py diff --git a/openpype/hosts/maya/plugins/create/create_look.py b/openpype/hosts/maya/plugins/create/create_look.py index cecdf9f54d..44e439fe1f 100644 --- a/openpype/hosts/maya/plugins/create/create_look.py +++ b/openpype/hosts/maya/plugins/create/create_look.py @@ -21,9 +21,6 @@ class CreateLook(plugin.Creator): # Whether to automatically convert the textures to .tx upon publish. self.data["maketx"] = self.make_tx - # Enable users to import reference - self.data["importReference"] = False - # Enable users to force a copy. # - on Windows is "forceCopy" always changed to `True` because of # windows implementation of hardlinks diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py new file mode 100644 index 0000000000..3e44addf6c --- /dev/null +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -0,0 +1,122 @@ +import os +import pyblish.api +from openpype.pipeline import publish, legacy_io +from openpype.settings import get_project_settings + + +def _get_project_setting(): + project_name = legacy_io.active_project() + project_setting = get_project_settings(project_name) + maya_enabled = ( + project_setting["maya"]["publish"]["ImportReference"]["enabled"] + ) + use_published = ( + project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["use_published"] + ) + if maya_enabled != use_published: + return False + else: + return use_published + + +class ImportReference(publish.Extractor): + """ + + Extract the scene with imported reference. + The temp scene with imported reference is + published for rendering if this extractor is activated + + """ + + label = "Import Reference" + order = pyblish.api.ExtractorOrder - 0.48 + hosts = ["maya"] + families = ["renderlayer", "workfile"] + active = _get_project_setting() + optional = True + tmp_format = "_tmp" + + def process(self, instance): + from maya import cmds + + ext_mapping = ( + instance.context.data["project_settings"]["maya"]["ext_mapping"] + ) + if ext_mapping: + self.log.info("Looking in settings for scene type ...") + # use extension mapping for first family found + for family in self.families: + try: + self.scene_type = ext_mapping[family] + self.log.info( + "Using {} as scene type".format(self.scene_type)) + break + except KeyError: + # no preset found + pass + + _scene_type = ("mayaAscii" + if self.scene_type == "ma" + else "mayaBinary") + + dir_path = self.staging_dir(instance) + # named the file with imported reference + tmp_name = instance.name + self.tmp_format + m_ref_fname = "{0}.{1}".format(tmp_name, self.scene_type) + + m_ref_path = os.path.join(dir_path, m_ref_fname) + + self.log.info("Performing extraction..") + current = cmds.file(query=True, sceneName=True) + cmds.file(save=True, force=True + + self.log.info("Performing extraction..") + + # create temp scene with imported + # reference for rendering + reference_node = cmds.ls(type="reference") + for r in reference_node: + rFile = cmds.referenceQuery(r, f=True) + if r == "sharedReferenceNode": + cmds.file(rFile, removeReference = True, referenceNode=r) + cmds.file(rFile, importReference=True) + + if current.endswith(self.scene_type): + current_path = os.path.dirname(current) + tmp_path_name = os.path.join(current_path, tmp_name) + cmds.file(rename=tmp_path_name) + cmds.file(save=True, force=True) + + with lib.maintained_selection(): + cmds.select(all=True, noExpand=True) + cmds.file(m_ref_path, + force=True, + typ = _scene_type, + exportSelected=True, + channels=True, + constraints=True, + shader=True, + expressions=True, + constructionHistory=True + ) + + if "files" not in instance.data: + instance.data["files"] = [] + + instance.data["files"].append(m_ref_path) + + if instance.data.get("representations") is None: + instance.data["representations"] = [] + + ref_representation = { + "name": self.scene_type, + "ext": self.scene_type, + "files": os.path.basename(m_ref_fname), + "stagingDir": dir_path + } + instance.data["representations"].append(ref_representation) + + self.log.info("Extracted instance '%s' to : '%s'" % (tmp_name, + m_ref_path)) + + cmds.file(current, open=True) diff --git a/openpype/hosts/maya/plugins/publish/extract_look.py b/openpype/hosts/maya/plugins/publish/extract_look.py index 845af0d32d..91b0da75c6 100644 --- a/openpype/hosts/maya/plugins/publish/extract_look.py +++ b/openpype/hosts/maya/plugins/publish/extract_look.py @@ -255,14 +255,6 @@ class ExtractLook(publish.Extractor): hashes = results["fileHashes"] remap = results["attrRemap"] - # Import Reference if the option is enabled - ref_import = instance.data.get("importReference", True) - if ref_import: - reference_node = cmds.ls(type="reference") - for r in reference_node: - rFile = cmds.referenceQuery(r, f=True) - cmds.file(rFile, importReference=True) - # Extract in correct render layer layer = instance.data.get("renderlayer", "defaultRenderLayer") with lib.renderlayer(layer): diff --git a/openpype/settings/defaults/project_settings/maya.json b/openpype/settings/defaults/project_settings/maya.json index 8643297f02..76be3c393e 100644 --- a/openpype/settings/defaults/project_settings/maya.json +++ b/openpype/settings/defaults/project_settings/maya.json @@ -762,6 +762,9 @@ } } }, + "ImportReference": { + "enabled": false + }, "ExtractMayaSceneRaw": { "enabled": true, "add_for_families": [ diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json index 53247f6bd4..4cf84795b5 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json @@ -62,7 +62,7 @@ } ] }, - { + { "type": "dict", "collapsible": true, "key": "ValidateFrameRange", @@ -807,6 +807,20 @@ "type": "schema", "name": "schema_maya_capture" }, + { + "type": "dict", + "collapsible": true, + "key": "ImportReference", + "label": "Extract Scenes with Imported Reference", + "checkbox_key": "enabled", + "children": [ + { + "type": "boolean", + "key": "enabled", + "label": "Enabled" + } + ] + }, { "type": "dict", "collapsible": true, From e5cf620575d535eb5415f8f0b22858c954fb5eb2 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:06:50 +0800 Subject: [PATCH 03/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 3e44addf6c..ac425ee083 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -1,4 +1,5 @@ import os + import pyblish.api from openpype.pipeline import publish, legacy_io from openpype.settings import get_project_settings @@ -11,8 +12,8 @@ def _get_project_setting(): project_setting["maya"]["publish"]["ImportReference"]["enabled"] ) use_published = ( - project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["use_published"] - ) + project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["use_published"] # noqa + ) if maya_enabled != use_published: return False else: From 06b982fd435c2549266cf400e47cbc3c3bb404f0 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:09:21 +0800 Subject: [PATCH 04/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index ac425ee083..feacf072c3 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -1,5 +1,5 @@ -import os +import os import pyblish.api from openpype.pipeline import publish, legacy_io from openpype.settings import get_project_settings @@ -10,7 +10,7 @@ def _get_project_setting(): project_setting = get_project_settings(project_name) maya_enabled = ( project_setting["maya"]["publish"]["ImportReference"]["enabled"] - ) + ) use_published = ( project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["use_published"] # noqa ) From 89b7699c21f9c0b55e5a4cdc2755bc242b7e12e9 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:10:48 +0800 Subject: [PATCH 05/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index feacf072c3..eb225127f0 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -1,6 +1,7 @@ - import os + import pyblish.api + from openpype.pipeline import publish, legacy_io from openpype.settings import get_project_settings From 2dc186f1911c2b5eebfa98e513a89831a51389ec Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:16:05 +0800 Subject: [PATCH 06/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index eb225127f0..56b757f2b4 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -1,5 +1,3 @@ -import os - import pyblish.api from openpype.pipeline import publish, legacy_io @@ -39,6 +37,7 @@ class ImportReference(publish.Extractor): tmp_format = "_tmp" def process(self, instance): + import os from maya import cmds ext_mapping = ( From bf7cca8586f485fb4507eef0cd050f6cd4cf481e Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:17:25 +0800 Subject: [PATCH 07/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 56b757f2b4..eb225127f0 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -1,3 +1,5 @@ +import os + import pyblish.api from openpype.pipeline import publish, legacy_io @@ -37,7 +39,6 @@ class ImportReference(publish.Extractor): tmp_format = "_tmp" def process(self, instance): - import os from maya import cmds ext_mapping = ( From 93c9ec8d16404bd17fd8de7c25c3bc5829402b20 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:22:52 +0800 Subject: [PATCH 08/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index eb225127f0..8be37c91e3 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -1,5 +1,7 @@ import os +from maya import cmds + import pyblish.api from openpype.pipeline import publish, legacy_io @@ -39,8 +41,6 @@ class ImportReference(publish.Extractor): tmp_format = "_tmp" def process(self, instance): - from maya import cmds - ext_mapping = ( instance.context.data["project_settings"]["maya"]["ext_mapping"] ) From 3ce41cbae8c7e0bb5b00951f8e7a9927df472da3 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:33:57 +0800 Subject: [PATCH 09/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 8be37c91e3..2f9e8516d7 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -70,7 +70,7 @@ class ImportReference(publish.Extractor): self.log.info("Performing extraction..") current = cmds.file(query=True, sceneName=True) - cmds.file(save=True, force=True + cmds.file(save=True, force=True) self.log.info("Performing extraction..") From 79e78beb61ef1c5f5bae9042a6b07db419fb79f8 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:36:24 +0800 Subject: [PATCH 10/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 2f9e8516d7..1ed109d720 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -6,6 +6,7 @@ import pyblish.api from openpype.pipeline import publish, legacy_io from openpype.settings import get_project_settings +from openpype.hosts.maya.api import lib def _get_project_setting(): @@ -80,7 +81,7 @@ class ImportReference(publish.Extractor): for r in reference_node: rFile = cmds.referenceQuery(r, f=True) if r == "sharedReferenceNode": - cmds.file(rFile, removeReference = True, referenceNode=r) + cmds.file(rFile, removeReference=True, referenceNode=r) cmds.file(rFile, importReference=True) if current.endswith(self.scene_type): @@ -93,14 +94,14 @@ class ImportReference(publish.Extractor): cmds.select(all=True, noExpand=True) cmds.file(m_ref_path, force=True, - typ = _scene_type, + typ=_scene_type, exportSelected=True, channels=True, constraints=True, shader=True, expressions=True, constructionHistory=True - ) + ) if "files" not in instance.data: instance.data["files"] = [] From 92a80eb24a4e9a849e58ef5ca57d885f9efa396a Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:38:08 +0800 Subject: [PATCH 11/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 1ed109d720..4035e8a9e6 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -101,7 +101,7 @@ class ImportReference(publish.Extractor): shader=True, expressions=True, constructionHistory=True - ) + ) if "files" not in instance.data: instance.data["files"] = [] From ab7ed6becbd100c6e9f8960065bdeffc8f609b5b Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 28 Sep 2022 18:39:22 +0800 Subject: [PATCH 12/29] Import Reference during Publish --- .../hosts/maya/plugins/publish/extract_import_reference.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 4035e8a9e6..cde8f67789 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -100,8 +100,7 @@ class ImportReference(publish.Extractor): constraints=True, shader=True, expressions=True, - constructionHistory=True - ) + constructionHistory=True) if "files" not in instance.data: instance.data["files"] = [] From ee78e9e67036308e651a9a0005b72a4d16ecce17 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 4 Oct 2022 15:45:17 +0800 Subject: [PATCH 13/29] Import Reference during Publish --- .../publish/extract_import_reference.py | 58 +++++++++---------- .../deadline/abstract_submit_deadline.py | 7 ++- .../defaults/project_settings/deadline.json | 1 + .../defaults/project_settings/maya.json | 3 - .../schema_project_deadline.json | 5 ++ .../schemas/schema_maya_publish.json | 14 ----- 6 files changed, 37 insertions(+), 51 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index cde8f67789..4cbc963cf3 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -9,22 +9,16 @@ from openpype.settings import get_project_settings from openpype.hosts.maya.api import lib -def _get_project_setting(): +def _import_reference(): project_name = legacy_io.active_project() project_setting = get_project_settings(project_name) - maya_enabled = ( - project_setting["maya"]["publish"]["ImportReference"]["enabled"] + import_reference = ( + project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["import_reference"] # noqa ) - use_published = ( - project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["use_published"] # noqa - ) - if maya_enabled != use_published: - return False - else: - return use_published + return import_reference -class ImportReference(publish.Extractor): +class ExtractImportReference(publish.Extractor): """ Extract the scene with imported reference. @@ -33,12 +27,11 @@ class ImportReference(publish.Extractor): """ - label = "Import Reference" + label = "Extract Import Reference" order = pyblish.api.ExtractorOrder - 0.48 hosts = ["maya"] families = ["renderlayer", "workfile"] - active = _get_project_setting() - optional = True + active = _import_reference() tmp_format = "_tmp" def process(self, instance): @@ -54,9 +47,10 @@ class ImportReference(publish.Extractor): self.log.info( "Using {} as scene type".format(self.scene_type)) break + except KeyError: - # no preset found - pass + # set scene type to ma + self.scene_type = "ma" _scene_type = ("mayaAscii" if self.scene_type == "ma" @@ -64,6 +58,8 @@ class ImportReference(publish.Extractor): dir_path = self.staging_dir(instance) # named the file with imported reference + if instance.name == "Main": + return tmp_name = instance.name + self.tmp_format m_ref_fname = "{0}.{1}".format(tmp_name, self.scene_type) @@ -72,23 +68,20 @@ class ImportReference(publish.Extractor): self.log.info("Performing extraction..") current = cmds.file(query=True, sceneName=True) cmds.file(save=True, force=True) - - self.log.info("Performing extraction..") - # create temp scene with imported # reference for rendering reference_node = cmds.ls(type="reference") for r in reference_node: - rFile = cmds.referenceQuery(r, f=True) + ref_file = cmds.referenceQuery(r, f=True) if r == "sharedReferenceNode": - cmds.file(rFile, removeReference=True, referenceNode=r) - cmds.file(rFile, importReference=True) + cmds.file(ref_file, removeReference=True, referenceNode=r) + return + cmds.file(ref_file, importReference=True) - if current.endswith(self.scene_type): - current_path = os.path.dirname(current) - tmp_path_name = os.path.join(current_path, tmp_name) - cmds.file(rename=tmp_path_name) - cmds.file(save=True, force=True) + cmds.file(rename=m_ref_fname) + cmds.file(save=True, force=True) + tmp_filepath = cmds.file(query=True, sceneName=True) + instance.context.data["currentFile"] = tmp_filepath with lib.maintained_selection(): cmds.select(all=True, noExpand=True) @@ -104,8 +97,7 @@ class ImportReference(publish.Extractor): if "files" not in instance.data: instance.data["files"] = [] - - instance.data["files"].append(m_ref_path) + instance.data["files"].append(m_ref_fname) if instance.data.get("representations") is None: instance.data["representations"] = [] @@ -113,12 +105,14 @@ class ImportReference(publish.Extractor): ref_representation = { "name": self.scene_type, "ext": self.scene_type, - "files": os.path.basename(m_ref_fname), - "stagingDir": dir_path + "files": m_ref_fname, + "stagingDir": os.path.dirname(tmp_filepath) } + instance.data["representations"].append(ref_representation) - self.log.info("Extracted instance '%s' to : '%s'" % (tmp_name, + self.log.info("Extracted instance '%s' to : '%s'" % (m_ref_fname, m_ref_path)) + #re-open the previous scene cmds.file(current, open=True) diff --git a/openpype/modules/deadline/abstract_submit_deadline.py b/openpype/modules/deadline/abstract_submit_deadline.py index 512ff800ee..909a5871e3 100644 --- a/openpype/modules/deadline/abstract_submit_deadline.py +++ b/openpype/modules/deadline/abstract_submit_deadline.py @@ -400,6 +400,7 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): label = "Submit to Deadline" order = pyblish.api.IntegratorOrder + 0.1 + import_reference = False use_published = True asset_dependencies = False @@ -516,7 +517,6 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): published. """ - instance = self._instance workfile_instance = self._get_workfile_instance(instance.context) if workfile_instance is None: @@ -524,7 +524,10 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): # determine published path from Anatomy. template_data = workfile_instance.data.get("anatomyData") - rep = workfile_instance.data.get("representations")[0] + if self.import_reference: + rep = workfile_instance.data.get("representations")[1] + else: + rep = workfile_instance.data.get("representations")[0] template_data["representation"] = rep.get("name") template_data["ext"] = rep.get("ext") template_data["comment"] = None diff --git a/openpype/settings/defaults/project_settings/deadline.json b/openpype/settings/defaults/project_settings/deadline.json index a6e7b4a94a..5f0731fb0c 100644 --- a/openpype/settings/defaults/project_settings/deadline.json +++ b/openpype/settings/defaults/project_settings/deadline.json @@ -25,6 +25,7 @@ "active": true, "tile_assembler_plugin": "OpenPypeTileAssembler", "use_published": true, + "import_reference": false, "asset_dependencies": true, "priority": 50, "tile_priority": 50, diff --git a/openpype/settings/defaults/project_settings/maya.json b/openpype/settings/defaults/project_settings/maya.json index 76be3c393e..8643297f02 100644 --- a/openpype/settings/defaults/project_settings/maya.json +++ b/openpype/settings/defaults/project_settings/maya.json @@ -762,9 +762,6 @@ } } }, - "ImportReference": { - "enabled": false - }, "ExtractMayaSceneRaw": { "enabled": true, "add_for_families": [ diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_deadline.json b/openpype/settings/entities/schemas/projects_schema/schema_project_deadline.json index cd1741ba8b..be95c682c4 100644 --- a/openpype/settings/entities/schemas/projects_schema/schema_project_deadline.json +++ b/openpype/settings/entities/schemas/projects_schema/schema_project_deadline.json @@ -130,6 +130,11 @@ "key": "use_published", "label": "Use Published scene" }, + { + "type": "boolean", + "key": "import_reference", + "label": "Use Scene with Imported Reference" + }, { "type": "boolean", "key": "asset_dependencies", diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json index 4cf84795b5..07d8f6aea0 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_maya_publish.json @@ -807,20 +807,6 @@ "type": "schema", "name": "schema_maya_capture" }, - { - "type": "dict", - "collapsible": true, - "key": "ImportReference", - "label": "Extract Scenes with Imported Reference", - "checkbox_key": "enabled", - "children": [ - { - "type": "boolean", - "key": "enabled", - "label": "Enabled" - } - ] - }, { "type": "dict", "collapsible": true, From 6f914a001de08931f84bf1753f0d3ad3bf903593 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 4 Oct 2022 15:46:12 +0800 Subject: [PATCH 14/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 4cbc963cf3..fd2687995b 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -114,5 +114,5 @@ class ExtractImportReference(publish.Extractor): self.log.info("Extracted instance '%s' to : '%s'" % (m_ref_fname, m_ref_path)) - #re-open the previous scene + # re-open the previous scene cmds.file(current, open=True) From df937a8e9ee028142ce4f56ea17c58e166b800ed Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 4 Oct 2022 16:11:26 +0800 Subject: [PATCH 15/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index fd2687995b..92426e97dd 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -32,6 +32,7 @@ class ExtractImportReference(publish.Extractor): hosts = ["maya"] families = ["renderlayer", "workfile"] active = _import_reference() + optional= True tmp_format = "_tmp" def process(self, instance): From dfd30d54601939ac31f72fa417a8bb00f67c5881 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 4 Oct 2022 16:13:21 +0800 Subject: [PATCH 16/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 92426e97dd..193048e9dc 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -32,7 +32,7 @@ class ExtractImportReference(publish.Extractor): hosts = ["maya"] families = ["renderlayer", "workfile"] active = _import_reference() - optional= True + optional = True tmp_format = "_tmp" def process(self, instance): From 590496814df787ba33a7bb366654fe14d8da76e3 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 7 Oct 2022 22:07:15 +0800 Subject: [PATCH 17/29] Import Reference during Publish --- .../publish/extract_import_reference.py | 70 ++++++++++++------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 193048e9dc..7448cf9966 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -1,9 +1,11 @@ import os +import sys from maya import cmds import pyblish.api +from openpype.lib import run_subprocess from openpype.pipeline import publish, legacy_io from openpype.settings import get_project_settings from openpype.hosts.maya.api import lib @@ -31,7 +33,7 @@ class ExtractImportReference(publish.Extractor): order = pyblish.api.ExtractorOrder - 0.48 hosts = ["maya"] families = ["renderlayer", "workfile"] - active = _import_reference() + active = True optional = True tmp_format = "_tmp" @@ -62,31 +64,48 @@ class ExtractImportReference(publish.Extractor): if instance.name == "Main": return tmp_name = instance.name + self.tmp_format - m_ref_fname = "{0}.{1}".format(tmp_name, self.scene_type) + current_name = cmds.file(query=True, sceneName=True) + ref_scene_name = "{0}.{1}".format(tmp_name, self.scene_type) - m_ref_path = os.path.join(dir_path, m_ref_fname) + reference_path = os.path.join(dir_path, ref_scene_name) self.log.info("Performing extraction..") - current = cmds.file(query=True, sceneName=True) - cmds.file(save=True, force=True) - # create temp scene with imported - # reference for rendering - reference_node = cmds.ls(type="reference") - for r in reference_node: - ref_file = cmds.referenceQuery(r, f=True) - if r == "sharedReferenceNode": - cmds.file(ref_file, removeReference=True, referenceNode=r) - return - cmds.file(ref_file, importReference=True) + script = ("import maya.standalone\nmaya.standalone.initialize()\n" + "cmds.file('{current_name}', open=True, force=True)\n" + "reference_node = cmds.ls(type='reference')\n" + "for ref in reference_node:\n" + "\tref_file = cmds.referenceQuery(ref, f=True)\n" + "\tif ref == 'sharedReferenceNode':\n" + "\t\tcmds.file(ref_file, removeReference=True, referenceNode=ref)\n" + "\telse:\n" + "\t\tcmds.file(ref_file, importReference=True)\n" + "try:\n" + "\tcmds.file(rename='{ref_scene_name}')\n" + "except SyntaxError:\n" + "\tcmds.file(rename='{ref_scene_name}')\n" + "cmds.file(save=True, force=True)\n") - cmds.file(rename=m_ref_fname) - cmds.file(save=True, force=True) - tmp_filepath = cmds.file(query=True, sceneName=True) + mayapy_exe = os.path.join(os.getenv("MAYA_LOCATION"), "bin", "mayapy") + if sys.platform == "windows": + mayapy_exe = mayapy_exe + ".exe" + + subprocess_args = [ + mayapy_exe, + "-c", + script.replace("\n", ";") + ] + try: + out = run_subprocess(subprocess_args) + except Exception: + self.log.error("Import reference failed", exc_info=True) + raise + + proj_file_dir = os.path.dirname(current_name) + tmp_filepath = os.path.join(proj_file_dir, ref_scene_name) instance.context.data["currentFile"] = tmp_filepath - with lib.maintained_selection(): cmds.select(all=True, noExpand=True) - cmds.file(m_ref_path, + cmds.file(reference_path, force=True, typ=_scene_type, exportSelected=True, @@ -98,7 +117,7 @@ class ExtractImportReference(publish.Extractor): if "files" not in instance.data: instance.data["files"] = [] - instance.data["files"].append(m_ref_fname) + instance.data["files"].append(ref_scene_name) if instance.data.get("representations") is None: instance.data["representations"] = [] @@ -106,14 +125,11 @@ class ExtractImportReference(publish.Extractor): ref_representation = { "name": self.scene_type, "ext": self.scene_type, - "files": m_ref_fname, - "stagingDir": os.path.dirname(tmp_filepath) + "files": ref_scene_name, + "stagingDir": proj_file_dir } instance.data["representations"].append(ref_representation) - self.log.info("Extracted instance '%s' to : '%s'" % (m_ref_fname, - m_ref_path)) - - # re-open the previous scene - cmds.file(current, open=True) + self.log.info("Extracted instance '%s' to : '%s'" % (ref_scene_name, + reference_path)) From 34b7ba9d3abead3437f7c53ea5d4d3abe3cd5720 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 12 Oct 2022 15:14:14 +0800 Subject: [PATCH 18/29] Import Reference during Publish --- .../publish/extract_import_reference.py | 38 ++++++++++--------- .../deadline/abstract_submit_deadline.py | 2 + .../defaults/project_anatomy/templates.json | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 7448cf9966..4ad3c7756d 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -70,20 +70,24 @@ class ExtractImportReference(publish.Extractor): reference_path = os.path.join(dir_path, ref_scene_name) self.log.info("Performing extraction..") - script = ("import maya.standalone\nmaya.standalone.initialize()\n" - "cmds.file('{current_name}', open=True, force=True)\n" - "reference_node = cmds.ls(type='reference')\n" - "for ref in reference_node:\n" - "\tref_file = cmds.referenceQuery(ref, f=True)\n" - "\tif ref == 'sharedReferenceNode':\n" - "\t\tcmds.file(ref_file, removeReference=True, referenceNode=ref)\n" - "\telse:\n" - "\t\tcmds.file(ref_file, importReference=True)\n" - "try:\n" - "\tcmds.file(rename='{ref_scene_name}')\n" - "except SyntaxError:\n" - "\tcmds.file(rename='{ref_scene_name}')\n" - "cmds.file(save=True, force=True)\n") + script = f""" + import maya.standalone + maya.standalone.initialize() + cmds.file('{current_name}', open=True, force=True) + reference_node = cmds.ls(type='reference') + for ref in reference_node: + ref_file = cmds.referenceQuery(ref, f=True) + if ref == 'sharedReferenceNode': + cmds.file(ref_file, removeReference=True, referenceNode=ref) + else: + cmds.file(ref_file, importReference=True) + try: + cmds.file(rename='{ref_scene_name}') + except SyntaxError: + cmds.file(rename='{ref_scene_name}') + + cmds.file(save=True, force=True) + """ mayapy_exe = os.path.join(os.getenv("MAYA_LOCATION"), "bin", "mayapy") if sys.platform == "windows": @@ -100,9 +104,7 @@ class ExtractImportReference(publish.Extractor): self.log.error("Import reference failed", exc_info=True) raise - proj_file_dir = os.path.dirname(current_name) - tmp_filepath = os.path.join(proj_file_dir, ref_scene_name) - instance.context.data["currentFile"] = tmp_filepath + instance.context.data["currentFile"] = ref_scene_name with lib.maintained_selection(): cmds.select(all=True, noExpand=True) cmds.file(reference_path, @@ -126,7 +128,7 @@ class ExtractImportReference(publish.Extractor): "name": self.scene_type, "ext": self.scene_type, "files": ref_scene_name, - "stagingDir": proj_file_dir + "stagingDir": os.path.dirname(current_name) } instance.data["representations"].append(ref_representation) diff --git a/openpype/modules/deadline/abstract_submit_deadline.py b/openpype/modules/deadline/abstract_submit_deadline.py index 909a5871e3..1f74b9b19b 100644 --- a/openpype/modules/deadline/abstract_submit_deadline.py +++ b/openpype/modules/deadline/abstract_submit_deadline.py @@ -526,6 +526,7 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): template_data = workfile_instance.data.get("anatomyData") if self.import_reference: rep = workfile_instance.data.get("representations")[1] + # template_data["workfiletype"] = rep.get("workfiletype") else: rep = workfile_instance.data.get("representations")[0] template_data["representation"] = rep.get("name") @@ -535,6 +536,7 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): anatomy = instance.context.data['anatomy'] anatomy_filled = anatomy.format(template_data) template_filled = anatomy_filled["publish"]["path"] + # template_filled = anatomy_filled["others"]["mayaWorkfile"]["path"] file_path = os.path.normpath(template_filled) self.log.info("Using published scene for render {}".format(file_path)) diff --git a/openpype/settings/defaults/project_anatomy/templates.json b/openpype/settings/defaults/project_anatomy/templates.json index caf399a903..72d387335d 100644 --- a/openpype/settings/defaults/project_anatomy/templates.json +++ b/openpype/settings/defaults/project_anatomy/templates.json @@ -17,7 +17,7 @@ }, "publish": { "folder": "{root[work]}/{project[name]}/{hierarchy}/{asset}/publish/{family}/{subset}/{@version}", - "file": "{project[code]}_{asset}_{subset}_{@version}<_{output}><.{@frame}><_{udim}>.{ext}", + "file": "{project[code]}_{asset}_{subset}_{@version}<_{output}><.{@frame}><_{udim}><_{workfiletype}>.{ext}", "path": "{@folder}/{@file}", "thumbnail": "{thumbnail_root}/{project[name]}/{_id}_{thumbnail_type}.{ext}" }, From de73dd7de6368dbc65e825d325d2058af14633d0 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 14 Oct 2022 21:27:10 +0800 Subject: [PATCH 19/29] Import Reference during Publish --- .../publish/extract_import_reference.py | 86 ++++++++++++------- .../deadline/abstract_submit_deadline.py | 2 - .../defaults/project_anatomy/templates.json | 2 +- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 4ad3c7756d..6b935ffb73 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -4,6 +4,7 @@ import sys from maya import cmds import pyblish.api +import tempfile from openpype.lib import run_subprocess from openpype.pipeline import publish, legacy_io @@ -33,7 +34,7 @@ class ExtractImportReference(publish.Extractor): order = pyblish.api.ExtractorOrder - 0.48 hosts = ["maya"] families = ["renderlayer", "workfile"] - active = True + active = _import_reference() optional = True tmp_format = "_tmp" @@ -68,43 +69,62 @@ class ExtractImportReference(publish.Extractor): ref_scene_name = "{0}.{1}".format(tmp_name, self.scene_type) reference_path = os.path.join(dir_path, ref_scene_name) + tmp_path = os.path.dirname(current_name) + "/" + ref_scene_name self.log.info("Performing extraction..") - script = f""" - import maya.standalone - maya.standalone.initialize() - cmds.file('{current_name}', open=True, force=True) - reference_node = cmds.ls(type='reference') - for ref in reference_node: - ref_file = cmds.referenceQuery(ref, f=True) - if ref == 'sharedReferenceNode': - cmds.file(ref_file, removeReference=True, referenceNode=ref) - else: - cmds.file(ref_file, importReference=True) - try: - cmds.file(rename='{ref_scene_name}') - except SyntaxError: - cmds.file(rename='{ref_scene_name}') - cmds.file(save=True, force=True) - """ + # This generates script for mayapy to take care of reference + # importing outside current session. It is passing current scene + # name and destination scene name. + script = (""" +# -*- coding: utf-8 -*- +'''Script to import references to given scene.''' +import maya.standalone +maya.standalone.initialize() +# scene names filled by caller +current_name = "{current_name}" +ref_scene_name = "{ref_scene_name}" +print(">>> Opening {{}} ...".format(current_name)) +cmds.file(current_name, open=True, force=True) +reference_node = cmds.ls(type='reference') +print(">>> Processing references") +for ref in reference_node: + ref_file = cmds.referenceQuery(ref, f=True) + print("--- {{}}".format(ref)) + print("--> {{}}".format(ref_file)) + if ref == 'sharedReferenceNode': + cmds.file(ref_file, removeReference=True, referenceNode=ref) + else: + cmds.file(ref_file, importReference=True) +print(">>> Saving scene as {{}}".format(ref_scene_name)) +cmds.file(rename=ref_scene_name) +cmds.file(save=True, force=True) +print("*** Done") + """).format(current_name=current_name, ref_scene_name=tmp_path) mayapy_exe = os.path.join(os.getenv("MAYA_LOCATION"), "bin", "mayapy") if sys.platform == "windows": - mayapy_exe = mayapy_exe + ".exe" + mayapy_exe += ".exe" + mayapy_exe = os.path.normpath(mayapy_exe) + # can't use TemporaryNamedFile as that can't be opened in another + # process until handles are closed by context manager. + with tempfile.TemporaryDirectory() as tmp_dir_name: + tmp_file_name = os.path.join(tmp_dir_name, "import_ref.py") + tmp = open(tmp_file_name, "w+t") + subprocess_args = [ + mayapy_exe, + tmp_file_name + ] + self.log.info("Using temp file: {}".format(tmp.name)) + try: + tmp.write(script) + tmp.close() + run_subprocess(subprocess_args) + except Exception: + self.log.error("Import reference failed", exc_info=True) + raise - subprocess_args = [ - mayapy_exe, - "-c", - script.replace("\n", ";") - ] - try: - out = run_subprocess(subprocess_args) - except Exception: - self.log.error("Import reference failed", exc_info=True) - raise - instance.context.data["currentFile"] = ref_scene_name with lib.maintained_selection(): cmds.select(all=True, noExpand=True) cmds.file(reference_path, @@ -117,6 +137,8 @@ class ExtractImportReference(publish.Extractor): expressions=True, constructionHistory=True) + instance.context.data["currentFile"] = tmp_path + if "files" not in instance.data: instance.data["files"] = [] instance.data["files"].append(ref_scene_name) @@ -128,8 +150,10 @@ class ExtractImportReference(publish.Extractor): "name": self.scene_type, "ext": self.scene_type, "files": ref_scene_name, - "stagingDir": os.path.dirname(current_name) + "stagingDir": os.path.dirname(current_name), + "outputName": "imported" } + self.log.info("%s" % ref_representation) instance.data["representations"].append(ref_representation) diff --git a/openpype/modules/deadline/abstract_submit_deadline.py b/openpype/modules/deadline/abstract_submit_deadline.py index 1f74b9b19b..909a5871e3 100644 --- a/openpype/modules/deadline/abstract_submit_deadline.py +++ b/openpype/modules/deadline/abstract_submit_deadline.py @@ -526,7 +526,6 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): template_data = workfile_instance.data.get("anatomyData") if self.import_reference: rep = workfile_instance.data.get("representations")[1] - # template_data["workfiletype"] = rep.get("workfiletype") else: rep = workfile_instance.data.get("representations")[0] template_data["representation"] = rep.get("name") @@ -536,7 +535,6 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): anatomy = instance.context.data['anatomy'] anatomy_filled = anatomy.format(template_data) template_filled = anatomy_filled["publish"]["path"] - # template_filled = anatomy_filled["others"]["mayaWorkfile"]["path"] file_path = os.path.normpath(template_filled) self.log.info("Using published scene for render {}".format(file_path)) diff --git a/openpype/settings/defaults/project_anatomy/templates.json b/openpype/settings/defaults/project_anatomy/templates.json index 72d387335d..caf399a903 100644 --- a/openpype/settings/defaults/project_anatomy/templates.json +++ b/openpype/settings/defaults/project_anatomy/templates.json @@ -17,7 +17,7 @@ }, "publish": { "folder": "{root[work]}/{project[name]}/{hierarchy}/{asset}/publish/{family}/{subset}/{@version}", - "file": "{project[code]}_{asset}_{subset}_{@version}<_{output}><.{@frame}><_{udim}><_{workfiletype}>.{ext}", + "file": "{project[code]}_{asset}_{subset}_{@version}<_{output}><.{@frame}><_{udim}>.{ext}", "path": "{@folder}/{@file}", "thumbnail": "{thumbnail_root}/{project[name]}/{_id}_{thumbnail_type}.{ext}" }, From 76a70b70cf75c83c2be3beae8897c17c9ad80cb0 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 14 Oct 2022 21:28:30 +0800 Subject: [PATCH 20/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 6b935ffb73..e70a27a6f6 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -124,7 +124,6 @@ print("*** Done") self.log.error("Import reference failed", exc_info=True) raise - with lib.maintained_selection(): cmds.select(all=True, noExpand=True) cmds.file(reference_path, From b82c3ac7f97d74272c4d991e7ec9a230cda6a5b4 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 14 Oct 2022 21:29:51 +0800 Subject: [PATCH 21/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index e70a27a6f6..3ec2f3bba4 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -66,7 +66,7 @@ class ExtractImportReference(publish.Extractor): return tmp_name = instance.name + self.tmp_format current_name = cmds.file(query=True, sceneName=True) - ref_scene_name = "{0}.{1}".format(tmp_name, self.scene_type) + ref_scene_name = "{0}.{1}".format(tmp_name, self.scene_type) reference_path = os.path.join(dir_path, ref_scene_name) tmp_path = os.path.dirname(current_name) + "/" + ref_scene_name From ab93c766ea425e6ef7b017465c6905cca014f712 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 25 Oct 2022 20:09:04 +0800 Subject: [PATCH 22/29] Import Reference during Publish --- .../plugins/publish/extract_import_reference.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 3ec2f3bba4..fa9e612dad 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -7,20 +7,10 @@ import pyblish.api import tempfile from openpype.lib import run_subprocess -from openpype.pipeline import publish, legacy_io -from openpype.settings import get_project_settings +from openpype.pipeline import publish from openpype.hosts.maya.api import lib -def _import_reference(): - project_name = legacy_io.active_project() - project_setting = get_project_settings(project_name) - import_reference = ( - project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["import_reference"] # noqa - ) - return import_reference - - class ExtractImportReference(publish.Extractor): """ @@ -34,10 +24,13 @@ class ExtractImportReference(publish.Extractor): order = pyblish.api.ExtractorOrder - 0.48 hosts = ["maya"] families = ["renderlayer", "workfile"] - active = _import_reference() optional = True tmp_format = "_tmp" + @classmethod + def apply_settings(cls, project_setting, system_settings): #noqa + cls.active = project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["import_reference"] # noqa + def process(self, instance): ext_mapping = ( instance.context.data["project_settings"]["maya"]["ext_mapping"] From fbfdefd8d4b487a161db7843e6f6995c1c45b88d Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 25 Oct 2022 20:09:38 +0800 Subject: [PATCH 23/29] Import Reference during Publish --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index fa9e612dad..b0b69304ef 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -28,7 +28,7 @@ class ExtractImportReference(publish.Extractor): tmp_format = "_tmp" @classmethod - def apply_settings(cls, project_setting, system_settings): #noqa + def apply_settings(cls, project_setting, system_settings): cls.active = project_setting["deadline"]["publish"]["MayaSubmitDeadline"]["import_reference"] # noqa def process(self, instance): From ef924a2358b883c8118fca413770881e544cf8d2 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 16 Nov 2022 21:00:17 +0800 Subject: [PATCH 24/29] Import Reference during Publish --- .../publish/extract_import_reference.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index b0b69304ef..8e0257dafb 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -79,16 +79,19 @@ current_name = "{current_name}" ref_scene_name = "{ref_scene_name}" print(">>> Opening {{}} ...".format(current_name)) cmds.file(current_name, open=True, force=True) -reference_node = cmds.ls(type='reference') print(">>> Processing references") -for ref in reference_node: - ref_file = cmds.referenceQuery(ref, f=True) - print("--- {{}}".format(ref)) - print("--> {{}}".format(ref_file)) - if ref == 'sharedReferenceNode': - cmds.file(ref_file, removeReference=True, referenceNode=ref) - else: - cmds.file(ref_file, importReference=True) +all_reference = cmds.file(q=True, reference=True) or [] +for ref in all_reference: + if cmds.referenceQuery(ref, f=True): + cmds.file(ref, importReference=True) + + nested_ref = cmds.file(q=True, reference=True) + if nested_ref: + for new_ref in nested_ref: + if new_ref not in all_reference: + all_reference.append(new_ref) + +print(">>> Finish importing references") print(">>> Saving scene as {{}}".format(ref_scene_name)) cmds.file(rename=ref_scene_name) From c86ebf1e93257ad29647797de57111bb1544fe08 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Fri, 23 Dec 2022 10:05:51 +0800 Subject: [PATCH 25/29] only allows the loaded reference to be imported reference --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index 8e0257dafb..b77740ae13 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -82,7 +82,7 @@ cmds.file(current_name, open=True, force=True) print(">>> Processing references") all_reference = cmds.file(q=True, reference=True) or [] for ref in all_reference: - if cmds.referenceQuery(ref, f=True): + if cmds.referenceQuery(ref, f=True, il=True): cmds.file(ref, importReference=True) nested_ref = cmds.file(q=True, reference=True) From df62f315cc60f72ff401992b2853b8fc47e1cd31 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 3 Jan 2023 23:45:51 +0800 Subject: [PATCH 26/29] drop out the force flag in referenceQuery --- openpype/hosts/maya/plugins/publish/extract_import_reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index b77740ae13..ce284d16fb 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -82,7 +82,7 @@ cmds.file(current_name, open=True, force=True) print(">>> Processing references") all_reference = cmds.file(q=True, reference=True) or [] for ref in all_reference: - if cmds.referenceQuery(ref, f=True, il=True): + if cmds.referenceQuery(ref, il=True): cmds.file(ref, importReference=True) nested_ref = cmds.file(q=True, reference=True) From ddb6ae8a5a38e2a408a701c47bc5484c485dbbd7 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Thu, 5 Jan 2023 12:25:55 +0800 Subject: [PATCH 27/29] import reference during publish --- .../plugins/publish/extract_import_reference.py | 16 ++++++---------- .../modules/deadline/abstract_submit_deadline.py | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/extract_import_reference.py b/openpype/hosts/maya/plugins/publish/extract_import_reference.py index ce284d16fb..51c82dde92 100644 --- a/openpype/hosts/maya/plugins/publish/extract_import_reference.py +++ b/openpype/hosts/maya/plugins/publish/extract_import_reference.py @@ -105,17 +105,13 @@ print("*** Done") # can't use TemporaryNamedFile as that can't be opened in another # process until handles are closed by context manager. with tempfile.TemporaryDirectory() as tmp_dir_name: - tmp_file_name = os.path.join(tmp_dir_name, "import_ref.py") - tmp = open(tmp_file_name, "w+t") - subprocess_args = [ - mayapy_exe, - tmp_file_name - ] - self.log.info("Using temp file: {}".format(tmp.name)) - try: + tmp_script_path = os.path.join(tmp_dir_name, "import_ref.py") + self.log.info("Using script file: {}".format(tmp_script_path)) + with open(tmp_script_path, "wt") as tmp: tmp.write(script) - tmp.close() - run_subprocess(subprocess_args) + + try: + run_subprocess([mayapy_exe, tmp_script_path]) except Exception: self.log.error("Import reference failed", exc_info=True) raise diff --git a/openpype/modules/deadline/abstract_submit_deadline.py b/openpype/modules/deadline/abstract_submit_deadline.py index 909a5871e3..155a647ff6 100644 --- a/openpype/modules/deadline/abstract_submit_deadline.py +++ b/openpype/modules/deadline/abstract_submit_deadline.py @@ -525,9 +525,9 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): # determine published path from Anatomy. template_data = workfile_instance.data.get("anatomyData") if self.import_reference: - rep = workfile_instance.data.get("representations")[1] + rep = workfile_instance.data["representations"][1] else: - rep = workfile_instance.data.get("representations")[0] + rep = workfile_instance.data["representations"][0] template_data["representation"] = rep.get("name") template_data["ext"] = rep.get("ext") template_data["comment"] = None From 2cf9b1ee6371d740c178451d1d65c6e7637df03c Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 10 Jan 2023 00:28:10 +0800 Subject: [PATCH 28/29] use current file for the scene rendering if the reference is imported --- openpype/modules/deadline/abstract_submit_deadline.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openpype/modules/deadline/abstract_submit_deadline.py b/openpype/modules/deadline/abstract_submit_deadline.py index 155a647ff6..f6750bc0f2 100644 --- a/openpype/modules/deadline/abstract_submit_deadline.py +++ b/openpype/modules/deadline/abstract_submit_deadline.py @@ -425,7 +425,11 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): file_path = None if self.use_published: - file_path = self.from_published_scene() + if not self.import_reference: + file_path = self.from_published_scene() + else: + self.log.info("use the scene with imported reference for rendering") # noqa + file_path = context.data["currentFile"] # fallback if nothing was set if not file_path: From 9301bf03fac16278f13eb094bc9116e8916328f4 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Tue, 10 Jan 2023 00:30:18 +0800 Subject: [PATCH 29/29] use current file for the scene rendering if the reference is imported --- openpype/modules/deadline/abstract_submit_deadline.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/openpype/modules/deadline/abstract_submit_deadline.py b/openpype/modules/deadline/abstract_submit_deadline.py index f6750bc0f2..648eb77007 100644 --- a/openpype/modules/deadline/abstract_submit_deadline.py +++ b/openpype/modules/deadline/abstract_submit_deadline.py @@ -528,10 +528,7 @@ class AbstractSubmitDeadline(pyblish.api.InstancePlugin): # determine published path from Anatomy. template_data = workfile_instance.data.get("anatomyData") - if self.import_reference: - rep = workfile_instance.data["representations"][1] - else: - rep = workfile_instance.data["representations"][0] + rep = workfile_instance.data["representations"][0] template_data["representation"] = rep.get("name") template_data["ext"] = rep.get("ext") template_data["comment"] = None