PDA

View Full Version : python MPlug.elementByPhysicalIndex


chadmv
12-12-2007, 01:12 AM
I'm writing a python script that accesses array attributes but I'm getting an error with the elementByPhysicalIndex function:

itDag = OpenMaya.MItDag( OpenMaya.MItDag.kDepthFirst, OpenMaya.MFn.kMesh )
while not itDag.isDone():
fnDepNode = OpenMaya.MFnDependencyNode( itDag.currentItem() )
print fnDepNode.name()
plugArray = fnDepNode.findPlug( "vrts" )
numElements = plugArray.numElements()
print "numElements = ", numElements
for i in range( numElements ):
# Get plug for i'th array element
print "Looking up index", i
plugCompound = plugArray.elementByPhysicalIndex( i )

itDag.next()

And the error I get from elementByPhysicalIndex

# Error: (kFailure): Unexpected Internal Failure
# Traceback (most recent call last):
# File "<maya console>", line 11, in ?
# File "C:\engserv\rbuild\164\build\wrk\optim\runTime\Python\Lib\site-packages\maya\OpenMaya.py", line 7914, in elementByPhysicalIndex
# RuntimeError: (kFailure): Unexpected Internal Failure #

I can't see anything wrong. Any ideas? thanks!

flaiver
12-12-2007, 08:56 AM
Cause I have just experience with Maya API and C++, I can only guess: Perhaps, you can check your plug with isArray first to get closer information. Perhaps, your plug is a child or a compound attribute? (no reason, why elementByPhyscalIndices have to fail, but in my eyes, your source looks fine)

chadmv
12-12-2007, 05:30 PM
I converted the exact same code to C++ and it works. Must be a Python issue.

CGTalk Moderation
12-12-2007, 05:30 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.