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
Summary
getChildren()
fails on some compounds. In those cases, children can be retrieved viaattributeQuery(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)]:
The most reliable workaround is to use
attributeQuery()
instead:Re-instantiating via
Attribute
works, but not always:This doesn't happen on all compounds: