Skip to content

Instantly share code, notes, and snippets.

@dvigne
Created June 11, 2019 18:35
Show Gist options
  • Save dvigne/a08680947dbe02dc548acc6206d01e88 to your computer and use it in GitHub Desktop.
Save dvigne/a08680947dbe02dc548acc6206d01e88 to your computer and use it in GitHub Desktop.
Class Maya Python File
import maya.cmds as cmds
import random
import time
# How many cubes to generate
numCubes = 50
# Clean up after?
cleanUpAfter = False
# Seed the NCSPRNG gerneator
random.seed(time.time())
# Detect if no cubes cubes in scene
if(len(cmds.ls("myCube*")) == 0):
# Spawn cubes using default d,w,h = 1 and auto-increment number
print("Generating Cubes 1 through %s" % numCubes)
for x in range(0, numCubes):
newCube = cmds.polyCube(name="myCube#", axis=[random.randrange(10),random.randrange(10), random.randrange(10)])
cmds.move(random.randrange(10), random.randrange(10), random.randrange(10), newCube)
# Else, randomize the cubes
else:
for cube in cmds.ls("myCube*"):
cmds.move(random.randrange(10), random.randrange(10), random.randrange(10), cube)
# Detect clean up state
if(cleanUpAfter):
# Remove all instances of myCube
cmds.delete(cmds.ls('myCube*'))
print("Clean up done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment