Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Maya: Maintain time connections on Alembic update. #4143

Merged
merged 4 commits into from
Dec 12, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions openpype/hosts/maya/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def update(self, container, representation):

# Need to save alembic settings and reapply, cause referencing resets
# them to incoming data.
alembic_attrs = ["speed", "offset", "cycleType"]
alembic_attrs = ["speed", "offset", "cycleType", "time"]
alembic_data = {}
if representation["name"] == "abc":
alembic_nodes = cmds.ls(
Expand All @@ -226,7 +226,15 @@ def update(self, container, representation):
if alembic_nodes:
for attr in alembic_attrs:
node_attr = "{}.{}".format(alembic_nodes[0], attr)
alembic_data[attr] = cmds.getAttr(node_attr)
inputs = cmds.listConnections(
node_attr, plugs=True, destination=False
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the code would be more readable if we'd move this to a simple separate function:

def get_input(attr):
    connections = cmds.listConnections(attr, plugs=True, destination=False)
    return connections[0] if connections else None

The code here could then just be:

                    data = {
                        "input": get_input(node_attr),
                        "value": cmds.getAttr(node_attr)
                    }

And further down would just be:

            if alembic_nodes:
                alembic_node = alembic_nodes[0]  # assume single AlembicNode
                for attr, data in alembic_data.items():
                    node_attr = "{}.{}".format(alembic_node, attr)
                    if data["input"]:
                        if data["input"] != get_input(node_attr):
                            cmds.connectAttr(
                                data["input"], node_attr, force=True
                            )
                    else:
                        input = get_input(node_attr)
                        if input:
                            cmds.disconnectAttr(input, node_attr)
                        cmds.setAttr(node_attr, data["value"])

Anyway, just feels more readable to only me maybe.

data = {
"input": None if inputs is None else inputs[0],
"value": cmds.getAttr(node_attr)
}

alembic_data[attr] = data
else:
self.log.debug("No alembic nodes found in {}".format(members))

Expand Down Expand Up @@ -263,8 +271,19 @@ def update(self, container, representation):
"{}:*".format(namespace), type="AlembicNode"
)
if alembic_nodes:
for attr, value in alembic_data.items():
cmds.setAttr("{}.{}".format(alembic_nodes[0], attr), value)
for attr, data in alembic_data.items():
node_attr = "{}.{}".format(alembic_nodes[0], attr)
if data["input"]:
cmds.connectAttr(
data["input"], node_attr, force=True
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this make sure that the connection to be made doesn't already exist? (is a warning issues when e.g. time was previously connected and you'd update (the update reconnects time by default) and thus this tries to connect time again even though already connected. Does that error or log a warning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note from testing side...it didnt reconnect time by default after updating the asset so no chance for any warning or error. If I am correct.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note from testing side...it didnt reconnect time by default after updating the asset so no chance for any warning or error. If I am correct.

Thank you - so did it just always result in an unconnected attribute, even if you previously had it connected? :)
Doesn't it by default connect to time?

else:
inputs = cmds.listConnections(
node_attr, plugs=True, destination=False
)
if inputs:
cmds.disconnectAttr(inputs[0], node_attr)
cmds.setAttr(node_attr, data["value"])

# Fix PLN-40 for older containers created with Avalon that had the
# `.verticesOnlySet` set to True.
Expand Down