From c161a637433bf8b7b0b211dced4c4a99c919ad47 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Wed, 19 Aug 2020 18:05:03 +0100 Subject: [PATCH 1/2] Fix alembic settings being reset when updating reference. --- pype/hosts/maya/plugin.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pype/hosts/maya/plugin.py b/pype/hosts/maya/plugin.py index ed244d56df..3b002eed10 100644 --- a/pype/hosts/maya/plugin.py +++ b/pype/hosts/maya/plugin.py @@ -174,6 +174,18 @@ class ReferenceLoader(api.Loader): assert os.path.exists(path), "%s does not exist." % path + # Need to save alembic settings and reapply, cause referencing resets + # them to incoming data. + alembic_attrs = ["speed", "offset", "cycleType"] + alembic_data = {} + if representation["name"] == "abc": + alembic_node = cmds.ls( + cmds.sets(node, query=True), type="AlembicNode" + )[0] + for attr in alembic_attrs: + node_attr = "{}.{}".format(alembic_node, attr) + alembic_data[attr] = cmds.getAttr(node_attr) + try: content = cmds.file(path, loadReference=reference_node, @@ -195,6 +207,21 @@ class ReferenceLoader(api.Loader): self.log.warning("Ignoring file read error:\n%s", exc) + # Reapply alembic settings. + if representation["name"] == "abc": + alembic_node = None + for member in cmds.sets(node, query=True): + shapes = cmds.listRelatives(member, shapes=True) + if shapes: + nodes = cmds.listConnections(shapes[0], type="AlembicNode") + if nodes: + alembic_node = nodes[0] + break + + for attr in alembic_attrs: + value = alembic_data[attr] + cmds.setAttr("{}.{}".format(alembic_node, attr), value) + # Fix PLN-40 for older containers created with Avalon that had the # `.verticesOnlySet` set to True. if cmds.getAttr("{}.verticesOnlySet".format(node)): From 91e65b1f15a3b7b5f795d0e6fbbbc6755a957391 Mon Sep 17 00:00:00 2001 From: Toke Stuart Jepsen Date: Thu, 20 Aug 2020 00:09:28 +0100 Subject: [PATCH 2/2] Safer alembic node search. --- pype/hosts/maya/plugin.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pype/hosts/maya/plugin.py b/pype/hosts/maya/plugin.py index 3b002eed10..a5c57f1ab8 100644 --- a/pype/hosts/maya/plugin.py +++ b/pype/hosts/maya/plugin.py @@ -179,12 +179,19 @@ class ReferenceLoader(api.Loader): alembic_attrs = ["speed", "offset", "cycleType"] alembic_data = {} if representation["name"] == "abc": - alembic_node = cmds.ls( - cmds.sets(node, query=True), type="AlembicNode" - )[0] - for attr in alembic_attrs: - node_attr = "{}.{}".format(alembic_node, attr) - alembic_data[attr] = cmds.getAttr(node_attr) + alembic_nodes = cmds.ls( + "{}:*".format(members[0].split(":")[0]), type="AlembicNode" + ) + if alembic_nodes: + for attr in alembic_attrs: + node_attr = "{}.{}".format(alembic_nodes[0], attr) + alembic_data[attr] = cmds.getAttr(node_attr) + else: + cmds.warning( + "No alembic nodes found in {}".format( + cmds.ls("{}:*".format(members[0].split(":")[0])) + ) + ) try: content = cmds.file(path, @@ -209,18 +216,13 @@ class ReferenceLoader(api.Loader): # Reapply alembic settings. if representation["name"] == "abc": - alembic_node = None - for member in cmds.sets(node, query=True): - shapes = cmds.listRelatives(member, shapes=True) - if shapes: - nodes = cmds.listConnections(shapes[0], type="AlembicNode") - if nodes: - alembic_node = nodes[0] - break - - for attr in alembic_attrs: - value = alembic_data[attr] - cmds.setAttr("{}.{}".format(alembic_node, attr), value) + alembic_nodes = cmds.ls( + "{}:*".format(members[0].split(":")[0]), type="AlembicNode" + ) + if alembic_nodes: + for attr in alembic_attrs: + value = alembic_data[attr] + cmds.setAttr("{}.{}".format(alembic_nodes[0], attr), value) # Fix PLN-40 for older containers created with Avalon that had the # `.verticesOnlySet` set to True.