From c0926104d59104cbc79d19296da70844ccc3fa21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Thu, 16 Nov 2023 18:29:31 +0100 Subject: [PATCH 1/4] :bug: handle empty materials list --- openpype/hosts/maya/plugins/publish/collect_look.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openpype/hosts/maya/plugins/publish/collect_look.py b/openpype/hosts/maya/plugins/publish/collect_look.py index db042963c6..16ae20e0ae 100644 --- a/openpype/hosts/maya/plugins/publish/collect_look.py +++ b/openpype/hosts/maya/plugins/publish/collect_look.py @@ -367,7 +367,11 @@ class CollectLook(pyblish.api.InstancePlugin): self.log.debug("Found the following sets:\n{}".format(look_sets)) # Get the entire node chain of the look sets # history = cmds.listHistory(look_sets, allConnections=True) - history = cmds.listHistory(materials, allConnections=True) + # if materials list is empty, listHistory() will crash with + # RuntimeError + history = [] + if materials: + history = cmds.listHistory(materials, allConnections=True) # Since we retrieved history only of the connected materials # connected to the look sets above we now add direct history From 319109be593940d282d9beb56a26b70e0cd76ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 24 Nov 2023 17:47:23 +0100 Subject: [PATCH 2/4] :bug: fix issue with render sets collection and inventory action --- .../plugins/inventory/import_modelrender.py | 11 ++---- .../maya/plugins/publish/collect_look.py | 39 +++++++++++++------ openpype/pipeline/actions.py | 7 ++++ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/openpype/hosts/maya/plugins/inventory/import_modelrender.py b/openpype/hosts/maya/plugins/inventory/import_modelrender.py index 4db8c4f2f6..3b30695146 100644 --- a/openpype/hosts/maya/plugins/inventory/import_modelrender.py +++ b/openpype/hosts/maya/plugins/inventory/import_modelrender.py @@ -33,7 +33,7 @@ class ImportModelRender(InventoryAction): ) def process(self, containers): - from maya import cmds + from maya import cmds # noqa: F401 project_name = get_current_project_name() for container in containers: @@ -66,7 +66,7 @@ class ImportModelRender(InventoryAction): None """ - from maya import cmds + from maya import cmds # noqa: F401 project_name = get_current_project_name() repre_docs = get_representations( @@ -85,12 +85,7 @@ class ImportModelRender(InventoryAction): if scene_type_regex.fullmatch(repre_name): look_repres.append(repre_doc) - # QUESTION should we care if there is more then one look - # representation? (since it's based on regex match) - look_repre = None - if look_repres: - look_repre = look_repres[0] - + look_repre = look_repres[0] if look_repres else None # QUESTION shouldn't be json representation validated too? if not look_repre: print("No model render sets for this model version..") diff --git a/openpype/hosts/maya/plugins/publish/collect_look.py b/openpype/hosts/maya/plugins/publish/collect_look.py index 16ae20e0ae..a9e967a094 100644 --- a/openpype/hosts/maya/plugins/publish/collect_look.py +++ b/openpype/hosts/maya/plugins/publish/collect_look.py @@ -69,9 +69,7 @@ def get_attributes(dictionary, attr, node=None): else: val = dictionary.get(attr, []) - if not isinstance(val, list): - return [val] - return val + return val if isinstance(val, list) else [val] def get_look_attrs(node): @@ -106,7 +104,7 @@ def get_look_attrs(node): def node_uses_image_sequence(node, node_path): - # type: (str) -> bool + # type: (str, str) -> bool """Return whether file node uses an image sequence or single image. Determine if a node uses an image sequence or just a single image, @@ -114,6 +112,7 @@ def node_uses_image_sequence(node, node_path): Args: node (str): Name of the Maya node + node_path (str): The file path of the node Returns: bool: True if node uses an image sequence @@ -247,7 +246,7 @@ def get_file_node_files(node): # For sequences get all files and filter to only existing files result = [] - for index, path in enumerate(paths): + for path in paths: if node_uses_image_sequence(node, path): glob_pattern = seq_to_glob(path) result.extend(glob.glob(glob_pattern)) @@ -358,6 +357,11 @@ class CollectLook(pyblish.api.InstancePlugin): for attr in shader_attrs: if cmds.attributeQuery(attr, node=look, exists=True): existing_attrs.append("{}.{}".format(look, attr)) + + print("-"*100) + print("existing_attrs: {}".format(existing_attrs)) + print("-"*100) + materials = cmds.listConnections(existing_attrs, source=True, destination=False) or [] @@ -377,13 +381,24 @@ class CollectLook(pyblish.api.InstancePlugin): # connected to the look sets above we now add direct history # for some of the look sets directly # handling render attribute sets - render_set_types = [ - "VRayDisplacement", - "VRayLightMesh", - "VRayObjectProperties", - "RedshiftObjectId", - "RedshiftMeshParameters", - ] + + # this needs to be done like this now, because Maya + # (at least 2024) crashes with Warning when render set type + # isn't available. cmds.ls() will return empty list + render_set_types = [] + if cmds.pluginInfo("vrayformaya", query=True, loaded=True): + render_set_types += [ + "VRayDisplacement", + "VRayLightMesh", + "VRayObjectProperties", + ] + + if cmds.pluginInfo("redshift4maya", query=True, loaded=True): + render_set_types += [ + "RedshiftObjectId", + "RedshiftMeshParameters", + ] + render_sets = cmds.ls(look_sets, type=render_set_types) if render_sets: history.extend( diff --git a/openpype/pipeline/actions.py b/openpype/pipeline/actions.py index feb1bd05d2..d89e2096ef 100644 --- a/openpype/pipeline/actions.py +++ b/openpype/pipeline/actions.py @@ -7,6 +7,8 @@ from openpype.pipeline.plugin_discover import ( deregister_plugin_path ) +from .load.utils import get_representation_path_from_context + class LauncherAction(object): """A custom action available""" @@ -100,6 +102,11 @@ class InventoryAction(object): """ return True + @classmethod + def filepath_from_context(cls, context): + return get_representation_path_from_context(context) + + # Launcher action def discover_launcher_actions(): From 6b4d0487acea25c67c1b4d1d64dfbd2e63fb7308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 24 Nov 2023 17:48:22 +0100 Subject: [PATCH 3/4] :dog: remove debug prints --- openpype/hosts/maya/plugins/publish/collect_look.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/collect_look.py b/openpype/hosts/maya/plugins/publish/collect_look.py index a9e967a094..11e87a8295 100644 --- a/openpype/hosts/maya/plugins/publish/collect_look.py +++ b/openpype/hosts/maya/plugins/publish/collect_look.py @@ -358,10 +358,6 @@ class CollectLook(pyblish.api.InstancePlugin): if cmds.attributeQuery(attr, node=look, exists=True): existing_attrs.append("{}.{}".format(look, attr)) - print("-"*100) - print("existing_attrs: {}".format(existing_attrs)) - print("-"*100) - materials = cmds.listConnections(existing_attrs, source=True, destination=False) or [] From 02342c864ddd62654699ae4351aeb9e76637bdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Mon, 27 Nov 2023 17:19:09 +0100 Subject: [PATCH 4/4] :recycle: filter render set types --- .../maya/plugins/publish/collect_look.py | 53 +++++++++---------- openpype/pipeline/actions.py | 1 - 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/openpype/hosts/maya/plugins/publish/collect_look.py b/openpype/hosts/maya/plugins/publish/collect_look.py index 11e87a8295..72682f7800 100644 --- a/openpype/hosts/maya/plugins/publish/collect_look.py +++ b/openpype/hosts/maya/plugins/publish/collect_look.py @@ -45,11 +45,23 @@ FILE_NODES = { "PxrTexture": "filename" } +RENDER_SET_TYPES = [ + "VRayDisplacement", + "VRayLightMesh", + "VRayObjectProperties", + "RedshiftObjectId", + "RedshiftMeshParameters", +] + # Keep only node types that actually exist all_node_types = set(cmds.allNodeTypes()) for node_type in list(FILE_NODES.keys()): if node_type not in all_node_types: FILE_NODES.pop(node_type) + +for node_type in RENDER_SET_TYPES: + if node_type not in all_node_types: + RENDER_SET_TYPES.remove(node_type) del all_node_types # Cache pixar dependency node types so we can perform a type lookup against it @@ -369,43 +381,30 @@ class CollectLook(pyblish.api.InstancePlugin): # history = cmds.listHistory(look_sets, allConnections=True) # if materials list is empty, listHistory() will crash with # RuntimeError - history = [] + history = set() if materials: - history = cmds.listHistory(materials, allConnections=True) + history = set( + cmds.listHistory(materials, allConnections=True)) # Since we retrieved history only of the connected materials # connected to the look sets above we now add direct history # for some of the look sets directly # handling render attribute sets - # this needs to be done like this now, because Maya - # (at least 2024) crashes with Warning when render set type + # Maya (at least 2024) crashes with Warning when render set type # isn't available. cmds.ls() will return empty list - render_set_types = [] - if cmds.pluginInfo("vrayformaya", query=True, loaded=True): - render_set_types += [ - "VRayDisplacement", - "VRayLightMesh", - "VRayObjectProperties", - ] - - if cmds.pluginInfo("redshift4maya", query=True, loaded=True): - render_set_types += [ - "RedshiftObjectId", - "RedshiftMeshParameters", - ] - - render_sets = cmds.ls(look_sets, type=render_set_types) - if render_sets: - history.extend( - cmds.listHistory(render_sets, - future=False, - pruneDagObjects=True) - or [] - ) + if RENDER_SET_TYPES: + render_sets = cmds.ls(look_sets, type=RENDER_SET_TYPES) + if render_sets: + history.update( + cmds.listHistory(render_sets, + future=False, + pruneDagObjects=True) + or [] + ) # Ensure unique entries only - history = list(set(history)) + history = list(history) files = cmds.ls(history, # It's important only node types are passed that diff --git a/openpype/pipeline/actions.py b/openpype/pipeline/actions.py index d89e2096ef..68533f7485 100644 --- a/openpype/pipeline/actions.py +++ b/openpype/pipeline/actions.py @@ -107,7 +107,6 @@ class InventoryAction(object): return get_representation_path_from_context(context) - # Launcher action def discover_launcher_actions(): return discover(LauncherAction)