TB1 Week 8


After having created a pyramid function, as well as a more streamlined version, I made a new version which would make a UI version usable in Maya. The major challenge however was making a version of the pyramid function which could have user inputted values.

To go about making the user input, I created a slider interface for them to change the amount of layers on the cube, which would in turn increase their scale. I did this using an intSliderGrp and the same improved pyramid function as before to plug the user inputted values into the function.

import maya.cmds

#A function that creates a pyramid of 3 cubes high

def Pyramid(width, height, depth):

   cmds.polyCube(w = width,h = height,d = depth)

   cmds.polyCube(w = width-1, h = height, d = depth-1)

   cmds.move(0,1,0)

   cmds.polyCube(w = width-2, h = height, d = depth-2)

   cmds.move(0,2,0)

   cmds.polyCube(w = width-3, h = height, d = depth-3)

   cmds.move(0,3,0)

#A function which creates a pyramid of a variable height

def PyramidFunction(base_size, height=1):

    #pulls the value of the slider into the function

    slider_value = cmds.intSliderGrp(int_slider, query=True, value=True) 

    #makes the value easier to call and gives it a clearer label

    base_size = slider_value

    #For loop that creates the repeating cubes

    for cube_dimensions in range(1, base_size+1):

        cmds.polyCube(w = cube_dimensions, h = height, d = cube_dimensions)

        cmds.move(base_size, moveY = True)

        base_size = base_size-1

        

def DeleteAll():

    cmds.select(all=True)

    cmds.delete()  

int_slider = "slider_name"       

#ensures the window is closed before attempting to open it

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

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

    

My_window = cmds.window("New_Window", title="Long Name", iconName='Short Name', widthHeight=(200, 55) )

cmds.columnLayout( adjustableColumn=True)

#button that does nothing

cmds.button( label='Do Nothing')

#creates a button which will close the window

cmds.button( label='Close', command=('cmds.deleteUI(\"New_Window", window=True)') )

#Basic pyramid function button

cmds.button( label='Pyramid', command= "Pyramid(4,1,4)")

#Slider used in the pyramid function

slider_value = cmds.intSliderGrp(int_slider, label = "slider_name", field=True, minValue = 3, maxValue = 50, value=1)

cmds.button(label='PyramidFunction', command= "PyramidFunction(slider_value,1)")

cmds.button(label="DeleteAll", command="DeleteAll()")

cmds.setParent('..')

cmds.showWindow( "New_Window" )

After having created a window version of the function, I was then told to create the pyramid function as a class. After having created the class version of my pyramid function, I then had to create a window which would let me interact with the class to create different pyramids.  

                                                                                  

import maya.cmds

class Pyramids:

    def __init__(self, base_size, height, layers):

        self.base_size = base_size

        self.height = height

        self.layers = layers

        

    #A function which creates a pyramid of a variable height

    def PyramidFunction(self):

        #For loop that creates the repeating cubes

        for cube_dimensions in range(1, self.base_size+1):

           cmds.polyCube(w = cube_dimensions, h = self.height, d = cube_dimensions)

           cmds.move(self.base_size, moveY = True)

           self.base_size = self.base_size-1

Pyramid Class Window

import maya.cmds

import Pyramid_Class

        

def DeleteAll():

    cmds.select(all=True)

    cmds.delete()  

int_slider = "slider_name"       

#ensures the window is closed before attempting to open it

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

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

    

My_window = cmds.window("New_Window", title="Long Name", iconName='Short Name', widthHeight=(200, 55) )

cmds.columnLayout( adjustableColumn=True)

#button that does nothing

cmds.button( label='Do Nothing')

#creates a button which will close the window

cmds.button( label='Close', command=('cmds.deleteUI(\"New_Window", window=True)') )

#Basic pyramid function button

cmds.button( label='Pyramid', command= "Pyramid(4,1,4)")

#Slider used in the pyramid function

slider_value = cmds.intSliderGrp(int_slider, label = "slider_name", field=True, minValue = 3, maxValue = 50, value=1)

cmds.button(label='PyramidFunction', command= "PyramidFunction(slider_value,1)")

cmds.button(label="SmallPyramid", command="Pyramids(3,1,3).PyramidFunction()")

cmds.button(label="MediumPyramid", command="Pyramids(5,1,5).PyramidFunction()")

cmds.button(label="LargePyramid", command="Pyramids(10,1,10).PyramidFunction()")

cmds.button(label="ThickPyramid", command="Pyramids(10,5,10).PyramidFunction()")

cmds.button(label="DeleteAll", command="DeleteAll()")

cmds.setParent('..')

cmds.showWindow( "New_Window" )

Leave a comment

Log in with itch.io to leave a comment.