Reputation: 11
I need to know how to generate some objects using Python in Maya, and then place them separated by 15 along X axis automatically. I tried to write a code but it did not work.
import maya.cmds as cmds
i = 0
while i < 10:
cmds.polyCube()
i = i + 1
objects = cmds.ls( type = "shape" )
for j in objects:
cmds.setAttr( "%s.translateX" % item, 15 )
Help me to solve my problem, please.
Upvotes: 1
Views: 2143
Reputation: 58093
For getting an expected result use this code:
import maya.cmds as mc
x = 0
y = 0
mc.polyCube( name = 'cube' )
for i in range(9):
mc.polyCube( name = 'cube' )
x += 15
y += 3
mc.move( x, y, 0 )
mc.select( all = True )
mc.scale( 5, 5, 5 )
Upvotes: 0
Reputation: 2512
you have to put the list return by maya command into variables.
for i in range(10):
cube = cmds.polyCube()
cubeTransform = cube[0] # cube is a list composed by cube transform name and polycube modificator
cmds.setAttr("%s.translateX" % cube[0],15)
Upvotes: 1