14/11/22


This time I wanted to add a slider to my pyramid creator window to adjust the size of the pyramid. This involved editing previous code in order to implement it and have it work correctly. The code for the window was:

import maya.cmds

def my_Function2(height,Slider):

    print(Slider)

    slider_value = cmds.intSlider(Slider, q = True, v = True)

    print(slider_value)

    for i in range(slider_value):

        cmds.polyCube(width = slider_value, depth = slider_value)

        cmds.move(0, height, 0)

        height = height+1

        slider_value = slider_value - 1

def DeleteAll():

    cmds.select(all = True)

    cmds.delete()

window = cmds.window( title="Pyramid", iconName="Short Name", widthHeight=(300, 135) )        

cmds.columnLayout( adjustableColumn=True )

pyramid_slider = cmds.intSlider( min=1, max=100, value=1, step=1)

cmds.button( label='Build Pyramid', command = "my_Function2(1,pyramid_slider)" )

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

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

cmds.setParent( '..' )

cmds.showWindow( window )

This brought up a window with a slider and 3 buttons all with their own functions. The slider when moved from left to right would mean the size of the pyramid would increase, with all the way to the right being as big as it can go. Then, the first button was "Create Pyramid" which was fairly self explanatory and would spawn in a pyramid to the size from the slider. The second button was a "Clear All", and therefore upon being pressed would delete all pyramids spawned from the window from the scene. The last button was a simple "Close" button which would close down the window.

Leave a comment

Log in with itch.io to leave a comment.