Archive for October, 2009

Code Snippet: Setting a matrix attribute with maya.cmds

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[103]', matrix)
Saturday, October 3rd, 2009 Main 2 Comments