Reputation: 1
I have just recently started writing Python code to be used in Maya.
My code looks like this:
import maya.cmds as cmds;
import random as rand;
for x in range (0,10):
cmds.polyCube(cmds.translateX == rand(0,100));
x += 1;
Maya then gives the error, 'module' has no attribute 'translateX'
I am not sure what is going on. Thank you!
Upvotes: 0
Views: 250
Reputation: 12218
translateX
isn't a command or part of the argument for a polyCube.
What you want is something more like
import maya.cmds as cmds;
import random as rand;
for x in range (10):
# create the cube at origin
cmds.polyCube()
# move it to a random X
cmds.xform( t = (rand.randrange(0,100), 0, 0) )
When you create the polyCube it will be selected, so issuing the xform()
immediately afterward will only affect the most recently created cube. You could also use cmds.setAttr(".translateX" = rand(0,100))
but that's less flexible if you also want to set the Y or Z directions
Upvotes: 2