getChildren() fails in cases where attributeQuery(listChildren=True) succeeds
Closed this issue · 1 comments
kimonmatara commented
Summary
getChildren()
fails on some compounds. In those cases, children can be retrieved via attributeQuery(listChildren=True)
instead.
Example
Under Maya 2023.1, Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)]:
import pymel.core as p
node = p.spaceLocator().getShape()
compound = node.attr('worldPosition')
compound.getChildren() # Fails with:
# ...general.py line 4376: (kFailure): Data type is not valid here
The most reliable workaround is to use attributeQuery()
instead:
childNames = p.attributeQuery('worldPosition', node=node, listChildren=True)
children = [node.attr(childName) for childName in childNames]
Re-instantiating via Attribute
works, but not always:
compound = str(compound)
compound = p.PyNode(compound)
compound.getChildren() # Succeeds, but not always
This doesn't happen on all compounds:
persp = p.PyNode('persp')
persp.attr('translate').getChildren() # Succeeds
kimonmatara commented
Scrap this--this is because worldPosition
is a multi + compound, and getChildren() has always failed on non-indexed multi-compounds.