[Question] Generating multiple polygon objects from a random number generator in Maya.

Hi, @Vaphell,

thanks for your reply!!! Here's what I already have at the moment. However, I can't seem to get the list of the polyStuff to sreturn.. Any way you can help me with that?? ===== import pymel.core as pm import random as rand

def randPrims(numPrims, maxSize, minX, maxX, minY, maxY, minZ, maxZ):

==== Randomizing the creation of Primitives ====

---- defining the random number variable. ---- #

rNum = rand.randint( 0, 4 ) radRandom = rand.randint( 1, 3 ) htRandom = rand.randint( 1, 3 )

def randList(): polyStuff = [] # ---- creating the list of things. '''

------ Create CV curves ------ #

def createCurves():

------ Create Cluster nodes ----- #

def createClus(): ''' def connectPrims(): sel = pm.selected() sel[0].type() if len(sel) != 2 : return if sel[0].type() != 'transform' or sel[1].type() != 'transform': return

def randomPlacements(obj): x = rand.randint(-50, 50) y = rand.randint(-50, 50) z = rand.randint(-50, 50) pm.move( x, y, z, obj ) xRot = rand.randint( 0, 360 ) yRot = rand.randint( 0, 360 ) zRot = rand.randint( 0, 360 ) pm.rotate( obj, xRot, yRot, zRot ) xyzScale = rand.randint( 1, 10 ) pm.scale( obj, xyzScale, xyzScale, xyzScale )

def makePolystuff(*args): # ---- looping a random number within the list polyStuff for i in range(0, 20): roll = rand.randint( 0, 4 )

    if roll == 0:
        makeCone = pm.polyCone( r = radRandom, height = htRandom, name = 'randomPrim#' )[0]
        polyStuff.append(makeCone)
        randomPlacements(makeCone)
    if roll == 1:
        makeCylinder = pm.polyCylinder( name = 'randomPrim#' )[0]
        polyStuff.append(makeCylinder)
        randomPlacements(makeCylinder)
    if roll == 2:
        makeCube = pm.polyCube( name = 'randomPrim#' )[0]
        polyStuff.append(makeCube)
        randomPlacements(makeCube)
    if roll == 3:
        makeSphere = pm.polySphere( name = 'randomPrim#' )[0]
        polyStuff.append(makeSphere)
        randomPlacements(makeSphere)
    if roll == 4:
        makePlane = pm.polyPlane( name = 'randomPrim#' )[0]
        polyStuff.append(makePlane)
        randomPlacements(makePlane)
return polyStuff

print polyStuff[0]
""" About this script """ def abt(*args): print 'Special thanks to Professor Mark Henne!' pm.confirmDialog( title = 'About', message = 'Created by Mandl ', messageAlign = 'center', button = 'OK')

""" Delete all the primitives """ def clearAll(args): temp = pm.ls('randomPrim') if len(temp) > 1: pm.delete(temp)

=================== UI STUFF ============================

# Check to see if there are any windows already open.

if pm.window("createPolys", exists = True): pm.deleteUI("createPolys")

# Creating our window 

pm.window('createPolys', title = "createPolys 1.0", w = 150, h = 50, mnb = False, mxb = False, sizeable = False) pm.columnLayout( adjustableColumn = True ) pm.button( label = 'Create Primitives', command = makePolystuff ) pm.button( label = 'Clear All Primitives', command = clearAll ) pm.button( label = 'About', command = abt ) pm.showWindow()

=================== UI STUFF ============================

/r/learnpython Thread Parent