Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / setAttr and matrix?
  RSS 2.0 ATOM  

setAttr and matrix?
Rate this thread
 
10080
 
Permlink of this thread   Subscribe to this thread
avatar
  • rob-hu
  • Posted: 24 March 2008 08:57 AM
  • Total Posts: 10
  • Joined: 02 November 2007 06:59 PM

Hi

Can someone show me how to use setAttr with matrix attribute in python please.

I have tried various things like (with an without the type="matrix")

cmds.setAttr("pSphere1.myMatrix", 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 , type="matrix")
cmds.setAttr("pSphere1.myMatrix", (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) , type="matrix")
cmds.setAttr("pSphere1.myMatrix",[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [1.0, 2.0, 3.0, 1.0]] , type="matrix")

mat = cmds.getAttr("pSphere1.test")
cmds.setAttr("pSphere1.myMatrix", mat , type="matrix")

but nothing seems to work.

Is this possible at all?

Thanks

Rob



Replies: 0
avatar
  • tkaap
  • Posted: 24 March 2008 09:47 PM

Hmm.  Nope.  It’s not possible.  I tried everything I can think of, too.  I’ve submitted this as a bug, because this syntax really should work:

cmds.setAttr("pSphere1.myMatrix", (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) , type="matrix")

You can get by for now by importing the maya.mel module and calling the Mel setAttr from python that way…
search here for “maya.mel” for the example:
( http://download.autodesk.com/us/...al&file=Using_Python.html )

-Tony



Replies: 0
avatar
  • rob-hu
  • Posted: 25 March 2008 04:40 AM

Hi,

Yeah we went for the maya.mel route in the end too.  Of course its not great, as in our situation we want to set the matrix values from a previous python calculation.  This means we need to convert our values to strings first which means we lose accuracy.

I guess a ‘hack’ around the accuracy problem would be to prehaps create a double array attribute as well.  From python set the doubleArray attribute values (I am guessing that works unlike the matrix!) and then run a mel script which does a getAttr to get the doubleArray into a mel float array and then sets the matrix attribute.  Somewhat unelegant though (as well as slow!).

Anyway thanks for the reply

Rob



Replies: 0
avatar
  • dodoer
  • Posted: 08 August 2009 01:34 AM

like this:
cmds.setAttr( ‘sphereShape.weights[0:6]’,1, 1, 2, 1, 1, 1, 2,size=7)



Replies: 1
/img/forum/dark/default_avatar.png

Hi,

I had the exact same problem and stumbled upon this thread. I then made a small python proc for setting a matrix attribute. It’s not pretty, but I wanted to share it with you guys anyway:

# 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 )

Though if you can use PyMel do that, as this should have all this stuff sorted.

Cheers,
Sune

Author: Nenox

Replied: 03 October 2009 04:46 AM  
avatar
  • Nenox
  • Posted: 03 October 2009 04:49 AM

Sorry that should have been a reply not a comment :-)



Replies: 0




   
  Settings Choose Theme color: