Maya Python Error

Maya Python Error

bayareadeck
Enthusiast Enthusiast
1,107 Views
2 Replies
Message 1 of 3

Maya Python Error

bayareadeck
Enthusiast
Enthusiast

Running Maya 2022.
In code below I would like to use
a variable with the setAttr() function
to move a locator to a different position.
Getting this error in the script editor:
line 2: Invalid argument 1, '['locator1']'. Expected arguments of type ( list, )


import maya.cmds as cmds
Loc = cmds.spaceLocator( p=(0, 0, 0))
cmds.setAttr(Loc,'.translate', 10,20,30)

0 Likes
Accepted solutions (1)
1,108 Views
2 Replies
Replies (2)
Message 2 of 3

mspeer
Consultant
Consultant
Accepted solution

Hi!

 

Try the following:

Loc = cmds.spaceLocator( p=(0, 0, 0))
cmds.setAttr(Loc[0]+'.translate', 10,20,30)
0 Likes
Message 3 of 3

bayareadeck
Enthusiast
Enthusiast

That was it !!

and shorter than this:

loc = mc.spaceLocator(p=(0, 0, 0))
mc.setAttr('{0}.translate'.format(loc[0]) , 10, 20, 30)

 

0 Likes