beginners question

39 views
Skip to first unread message

jettam

unread,
Aug 29, 2017, 7:27:07 PM8/29/17
to Python Programming for Autodesk Maya
I'm really new to python, and I've been doing some tutorials on youtube.

This simple script makes a cube 10 times and stacks it 1 unit on top of itself. I want to know how can I make it stack 2 units ontop or any arbitrary number I give it?   
Thanks in advance. 



import maya.cmds as cmds

cubeList = cmds.ls( 'myCube*' )
if len(cubeList) >0:
    cmds.delete(cubeList)

result = cmds.polyCube(w=1, h=1, d=1, name='myCube#')
transformName = result[0]

for i in range (0,10):
    instanceResult= cmds.instance(transformName, name='%s_inst#' % (transformName))
    cmds.move(x,i,z, instanceResult)
    

Ravi Jagannadhan

unread,
Aug 29, 2017, 8:04:26 PM8/29/17
to python_in...@googlegroups.com
In your loop, multiply i by your increment of choice. So, if you're trying to do an increment of 2, the cubes would be at:

x, 0, z
x, 2, z
x, 4, z

and so on.



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b8c48d5f-b79d-4ddf-ae6f-d77df218bd48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Where we have strong emotions, we're liable to fool ourselves - Carl Sagan

Simon Anderson

unread,
Aug 29, 2017, 8:07:48 PM8/29/17
to Python Programming for Autodesk Maya
Hi jettam, 

the piece of code that is making your objects move incrementally is the:

for i in range (0,10):
    cmds.move(x,i,z, instanceResult)

if you want each block to move a specific amount per a loop:

offsetPerIndex = 2
for i in range (0,10):
    y = i * (offsetPerIndex + 1) # 1 represents the object size
    cmds.move(x,y,z, instanceResult)

jettam

unread,
Aug 29, 2017, 10:28:37 PM8/29/17
to Python Programming for Autodesk Maya
Thank you. 
Reply all
Reply to author
Forward
0 new messages