The other day, I encountered a problem when I tried to write a sample for Maya 2016.
When I was trying to get an element in an array using a physical index, it worked fine most of the time. But it failed, when I was trying to get the elements inside a CV array. This time it returned an incorrect number of elements and thrown an error when I was accessing the array. It turned out that physical index is safe to use for user created nodes but for Maya internal objects like CV, we should use logical index instead:
indices = OpenMaya.MIntArray()
plug.getExistingArrayAttributeIndices(indices)
for plugArrayIndex in indices:
arrayPlug = plug.elementByLogicalIndex(plugArrayIndex)
The code above is using the logical index like we do in MEL. It is safer than physical index and can be used for all kinds of Maya internal array objects :)
Do you find any traps in your Maya programming? Please share with us!
Comments
You can follow this conversation by subscribing to the comment feed for this post.