From 0b60e9c112bb438776220c32f3e052cb2cf7c243 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Fri, 18 Jun 2021 08:45:35 +0100 Subject: [PATCH] Handle attribute elements, this was a bug! --- cmdx.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/cmdx.py b/cmdx.py index db635be..96f8ed1 100644 --- a/cmdx.py +++ b/cmdx.py @@ -2652,13 +2652,13 @@ def __getitem__(self, logicalIndex): >>> plug[1] << tm["parentMatrix"][0] >>> plug[2] << tm["worldMatrix"][0] - >>> plug[2].connection(plug=True) == tm["worldMatrix"] + >>> plug[2].connection(plug=True) == tm["worldMatrix"][0] True # Notice how index 2 remains index 2 even on disconnect # The physical index moves to 1. >>> plug[1].disconnect() - >>> plug[2].connection(plug=True) == tm["worldMatrix"] + >>> plug[2].connection(plug=True) == tm["worldMatrix"][0] True """ @@ -3804,6 +3804,12 @@ def connections(self, True >>> a["ihi"] 2 + >>> b["arrayAttr"] = Long(array=True) + >>> b["arrayAttr"][0] >> a["ihi"] + >>> a["ihi"].connection() == b + True + >>> a["ihi"].connection(plug=True) == b["arrayAttr"][0] + True """ @@ -3820,7 +3826,27 @@ def connections(self, # sometimes, we have to convert them before using them. # https://forums.autodesk.com/t5/maya-programming/maya-api-what-is-a-networked-plug-and-do-i-want-it-or-not/td-p/7182472 if plug.isNetworked: - plug = node.findPlug(plug.partialName()) + + if plug.isElement: + # Name would be e.g. 'myArrayAttr[0]' + # raise TypeError(plug.partialName() + "\n") + name = plug.partialName() + + if name.endswith("]"): + name, index = name.rsplit("[", 1) + index = int(index.rstrip("]")) + + else: + # E.g. worldMatrix[0] -> wm + index = 0 + + plug = node.findPlug(name) + + # The index returned is *logical*, not physical. + plug = plug.elementByLogicalIndex(index) + + else: + plug = node.findPlug(plug.partialName()) yield Plug(node, plug, unit) else: @@ -4948,7 +4974,7 @@ def exists(path, strict=True): return False if strict: - return node.path(namespace=True) == path + return node.path() == path return True