#So i did a quick test and i post a incorrect answer previously:
import maya.cmds
import maya.OpenMaya
targetNode = maya.cmds.createNode('transform')
maya.cmds.addAttr(targetNode, ln='input', m=True, v=True)
for index in [12, 13, 16, 23]:
maya.cmds.setAttr('{0}.input[{1}]'.format(targetNode, index), index)
selList = maya.OpenMaya.MSelectionList()
maya.OpenMaya.MGlobal.getSelectionListByName(targetNode, selList)
depNode = maya.OpenMaya.MObject()
selList.getDependNode(0, depNode)
depUtils = maya.OpenMaya.MFnDependencyNode(depNode)
inputPlug = depUtils.findPlug('input')
print inputPlug.name()
indices = maya.OpenMaya.MIntArray()
inputPlug.getExistingArrayAttributeIndices(indices)
print indices
print inputPlug.numElements()
indexToRead = 0
print inputPlug.elementByPhysicalIndex(indexToRead).name()
#-----------------------------------------------------------------------------------------------------------------------
"""
*elementByPhysicalIndex(indexToRead) == indices[indexToRead]*
elementByPhysicalIndex refers to relative index in your array
elementByLogicalIndex will mostly point out to the connection *slot *of the
attribute ( the element hosting the data )
what is dangerous if you use elementByLogicalIndex is that maya will create
an input/output element at this connection index if its empty(its the
standard behavior by the way).
in your datablock it migh be better to avoid using MPlug ( you can do
everything cleanly with attribute).
"""
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/f143efee-cf80-4cb4-acd1-97ad44656d1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.