Skip to content

Commit

Permalink
Handle attribute elements, this was a bug!
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso committed Jun 18, 2021
1 parent 1b8195c commit 0b60e9c
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions cmdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
"""

Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0b60e9c

Please sign in to comment.