Skip to content

Instantly share code, notes, and snippets.

@thomashope
Last active October 22, 2015 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomashope/6ae71475a471de58d7c8 to your computer and use it in GitHub Desktop.
Save thomashope/6ae71475a471de58d7c8 to your computer and use it in GitHub Desktop.
import maya.cmds as cmds
# what to call the army
army_name = "Toms_dangerous_cubes"
cmds.group(empty=True, name=army_name)
# how many rows and columns the army should have
rows = 5;
cols = 5;
# execute this line individualy to get more information in the output pane
cmds.help("polyCube")
for z_pos in range(rows):
for x_pos in range(cols):
# create a cube and set the dimensions
object = cmds.polyCube(width=0.8,
height=2,
depth=0.8)
# place the 'soldiers' so the army is centered at the origin
cmds.xform(t=(x_pos - width/2,
1,
z_pos - depth/2))
# set the new name of the soldier based on it's position in the formation
new_name = "soldier_" + str(x_pos) + "_" + str(z_pos)
# edit the name of previously made object
# (you could also just use the -name flag when creating it
cmds.rename(object[0], new_name)
cmds.group(new_name, parent=army_name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment