PDA

View Full Version : trying to use the API in python.. again


sheb
02-05-2008, 11:28 AM
Hello!

Once more I'm trying to use the Maya API via python .. and again I can't get it to work properly. What I want to do is using the api Matrix class to create the inverse of the one I retrieved from the xform command.


#get the inverse matrix using the maya api
def inverseMatrix(m):
newM = []
for i in range(0,4):
newM.append([0,0,0,0])
for y in range(0,4):
newM[i][y]=m[y*4+i]


ma = om.MMatrix(newM).inverse()

for i in range(0,4):
for y in range(0,4):
newM[y*4+i]=ma[i][y]


return newM




I'm converting the matrix from float[16] to float[4][4] but the function seems to want 'float const [4][4]' and I have no idea how to create it. I know there is the MScriptUtility class for making pointers and references but it doesnt seem to help there.
Does anybody know how to do this? I guess I could use some math library for python but I wanted to get more familiar using the API .. :/

Thanks for any hints!
seb

BenBarker
02-06-2008, 10:37 PM
Try this to get and set an MMatrix from a list:


def getMMatrix(inputList):
matrix = mOpenMaya.MMatrix()
mOpenMaya.MScriptUtil.createMatrixFromList(inputList, matrix)
return matrix

def setMMatrix(inputMatrix):
returnList = []
for row in range(0,4):
for col in range(0,4):
matrixValue = 0.0
matrixValue = mOpenMaya.MScriptUtil.getDoubleArrayItem(inputMatrix[row] , col)
returnList.append( matrixValue )
return returnList

CGTalk Moderation
02-06-2008, 10:37 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.