import maya.cmds as mc
import random
def distributeObjects(stairs=None):
''' This will make and randomly distribute a spiralStaircase '''
checkTest = 0
def makestairs():
''' first make one spiral staircase '''
# make a dictionary
steps = {'name':'Step','slide':5,'rotations':10,'spacing':1,'stepDepth':2,'stepHeight':.75}
stepName=steps.get('name')
# make masterGroup
groupAllSteps = mc.group(name="Group"+stepName+"s", empty=True)
for x in range (0,100):
#make stairs
# make step
stepObj = mc.polyCube(name=stepName+"#", w=5, h=steps.get('stepHeight'), d=steps.get('stepDepth'), ch=0)
# make group
stepGrp = mc.group(empty=True, name=stepName+'_Grp#')
# parent stepObj to stepGrp
mc.parent(stepObj, stepGrp)
# rotate stepGrp
mc.xform(stepGrp, ro=(0,(steps.get('rotations')*x),0))
# transform stepObj
mc.xform(stepObj[0], t=(steps.get('slide'),steps.get('stepHeight')*steps.get('spacing')*x,0))
# parent stepObj to masterGroup
mc.parent(stepObj, groupAllSteps)
# delete stepGrp
mc.delete(stepGrp)
checkTest = 1
def distributeStairs():
''' duplicate the pre-made spiral staircase X amount of times, and randomly distribute them '''
for i in range (stairs):
trX = random.uniform(-30,30)
trY = random.uniform(-30,30)
trZ = random.uniform(-30,30)
newGroup = mc.duplicate(GroupSteps,name=GroupSteps+i)
mc.setAttr(newGroup+".translate",trX,trY,trZ,type='double3')
if stairs >= 1:
makestairs()
if checkTest == 1:
distributeStairs()
distributeObjects(3)