Seems you just can’t do it.. So use mel,PyMel or maya.OpenMaya!
However if can’t or won’t do neither, you can use this tiny procedure that will do it for you (using maya.mel):
# The proc import maya.cmds as mc import maya.mel as mel def setMatrixAttr(obj, attr, matrixList): matrixString = '' for element in matrixList: matrixString = matrixString + str(element) + '' mel.eval("setAttr -type \"matrix\" " + obj + "." + attr + matrixString) # Example of usage matrix = mc.getAttr(’LeftLeg.worldInverseMatrix’) setMatrixAttr('skinCluster51', 'bindPreMatrix', matrix)
2 thoughts on “Code Snippet: Setting a matrix attribute with maya.cmds”
have you considered using “xform” function in .mel to set matrices? If so, why are you not using them here? I’m having trouble setting a matrix by hand in Maya with data in text file. Was wondering if you had similar problems.
For this example I’m trying to set the .bindPreMatrix attribute of a skin cluster and I’m not sure this can be done with the xform command. Actually I don’t think I ever tried to set a matrix with the xform command.. If you want, I would be glad to have a look at your problem code.