pyramid script 2nd draft


import maya.cmds #import maya

class pyramid:

    def floor(self):

        if cmds.objExists('pPlane1'):

            cmds.delete('pPlane1')

        cmds.polyPlane(w=2400, h=2400) #floorplane

        cmds.move(0,-0.5,0) #moves down slightly

        floor_set = cmds.sets(n='floor_set')

        cmds.select(d=True) #selects object

        

    def fixed(self, layers):

        if cmds.objExists('cube_set'):

            cmds.select('cube_set')

            cmds.delete() #15-17 deletes existing cube set

        cube_list = []

        for i in range(layers): #one loop for each layer

            dimension=((layers*2)-(i*2)) #start size vary depending on no. of layers

            cube = cmds.polyCube(w=dimension, d=dimension)

            cmds.move(0,(i),0)

            cube_list.append(cube[0]) #adds to list of cubes created by the function

        cmds.select(cube_list)  

        cube_set = cmds.sets(n='cube_set') #adds created cube(s) to their own set

        cmds.select('cube_set')            #and selects set

                   

    def clamp(self, num, min_value, max_value):

        return max(min(num, max_value), min_value) #constrains a value

    def custom(self, custom_layer_field):

        custom_layer = cmds.intField(custom_layer_field, query = True, value = True) #gets value entered from intfield

        adjust_layer = self.clamp(custom_layer, 1, 1000) #only will adjust if x<1 or x>1000

        if adjust_layer!=custom_layer: #check if adjustment was made

            print ("Value outside the range of 1 to 1000. Adjusted accordingly.")

        self.fixed(adjust_layer)

        

    def del_cube(self):

        if cmds.objExists('cube_set'): #'if' checks that there is something to delete or not

            cmds.select('cube_set')

            cmds.delete()

        else:

            print("There are no cubes to delete yet!")

        

    def del_floor(self): 

        if cmds.objExists('floor_set'): #same as del_cube() but floorplane

            cmds.select('floor_set')

            cmds.delete()

        else:

            print("There is no floor to delete yet!")

    

p=pyramid() #program needs an example of the class being referenced or it gets weird

    

if cmds.window("new_window", exists=True):

    cmds.deleteUI("new_window", window=True)

window = cmds.window( "new_window", title="'.py'ramids", widthHeight=(400, 700), bgc=(1,0.8,0.7)) #defining window

cmds.columnLayout( adjustableColumn=True )

cmds.button( label='Create Floor',c='p.floor()', height=30, bgc=(1,0.85,0))

cmds.button( label='10 Layers.',c='p.fixed(10)', height=30, bgc=(1,0.85,0))

cmds.button( label='20 Layers?',c='p.fixed(20)', height=50, bgc=(0.88,0.6,0.05)) #buttons

cmds.button( label='30 LAYERS!',c='p.fixed(30)', height=70, bgc=(0.98,0.42,0))

cmds.button( label='CUSTOM LAYERS!!! (type below: 1 to 1000)',c='p.custom(custom_layer_field)', height=90, bgc=(0.88,0.18,0.05))

custom_layer_field = cmds.intField( minValue=1, maxValue=1000, v=1, bgc=(0.88,0.18,0.05))#integer input field

cmds.button( label='Delete Cubes', command=('p.del_cube()'), height=40, bgc=(1,0,0))

cmds.button( label='Delete Floor', command=('p.del_floor()'), height=40, bgc=(1,0,0))

cmds.button( label='Delete All', command=('cmds.file(f=True, new=True)'), height=40, bgc=(1,0,0))

cmds.button( label='Close Menu', command=('cmds.deleteUI("new_window", window=True)'), height=40, bgc=(1,0,0))

cmds.setParent( '..' )

cmds.showWindow( window )

Leave a comment

Log in with itch.io to leave a comment.