When to use Logical Indicies over Physical Indicies

83 views
Skip to first unread message

Dylan Smith

unread,
Oct 26, 2016, 4:42:44 AM10/26/16
to Python Programming for Autodesk Maya
Hey Everyone,
I was hoping someone could clear up something for me. When would we want to use Logical indexes instead of Physical ones.
I've been reading through some documentation and the MPlug Class Reference explains what they are, but not when we should use one or the other.
From my understanding of the Maya API, I can't think of a reason to ever use Logical indexes . To me it just seems like an unnecessary source of potential confusion and bugs. 
If I'm using physical indexes then I know that the second plug will always be index 1. But with logical indexes it could be anything. The physical option seems like the more appealing,
but if both options are in there then I assume there's a good reason for it. What am I missing here? I've tried searching the documentation for an answer but am yet to find anything.

Thanks in advance for any help :)
Dylan

Cedric Bazillou

unread,
Oct 26, 2016, 3:31:50 PM10/26/16
to Python Programming for Autodesk Maya
Its a really robust and flexible mechanism which makes perfect sense in a nodal application...
Array attribute ( vertical one like ouput[0], output[n] ) can potentially be sparse : it means no contiguous so inputGeometry[12], inputGeometry[13], inputGeometry[26] are perfectly valid
let say you have an iterator in your deformer what you are interested in is process element and not attached to physical index you need to extract to access these data.

How much experience do you have with maya ?

Dylan Smith

unread,
Oct 26, 2016, 8:33:25 PM10/26/16
to python_in...@googlegroups.com
I've used Maya a fair bit, but I've only just started working with the API and the Node side of things. Before this I've mainly used it for modelling and UV'ing. Though I've also used Houdini a bunch so I am familiar with Node based workflows. With your example of the 'inputGeometry' attribute, from what I've read from the documentation (the specific page I'm referring to is linked below) it seems like instead of using Logical Indexes 12, 13, and 26 to access those three plugs, I could simply use Physical Indexes of 0, 1, and 2 instead. From what you're saying I'm guessing this is incorrect, but I'm not sure why. Would you be able to expand on the iterator explanation please? I don't quite understand it.


--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/HPX99HYdGts/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/27b3a353-3f66-4195-8975-0554c8c95d3a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Cedric Bazillou

unread,
Oct 27, 2016, 3:18:47 PM10/27/16
to Python Programming for Autodesk Maya
I dont have maya at work but from what you wrote i think you understood it the reverse way your physical index are 12, 13, 26.
Maya when it will process the datablock work on them in a sorted order so the logical index 0 will refer to physical index 12  (1 -> 13) and so on.


Cedric Bazillou

unread,
Oct 27, 2016, 5:23:45 PM10/27/16
to Python Programming for Autodesk Maya
#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).
"""

Reply all
Reply to author
Forward
0 new messages