how to add a intslider to button


import maya.cmds

def Pyramid():

    

    pyramid_height = 20 

    

    for x in range(1,pyramid_height):   

        cmds.polyCube(w=1, h= 1, d= 1)

        cmds.move(x ,moveY = True)

        cmds.scale(pyramid_height,pyramid_height, scaleXZ = True)

        pyramid_height = pyramid_height - 1

        

##################ADDING A SLIDER#################################################        

def Pyramid_custom(slider_value):

    

    pyramid_height = cmds.intSlider(slider_value, query=True, value=True)

    

    for x in range(1,pyramid_height):   

        cmds.polyCube(w=1, h= 1, d= 1)

        cmds.move(x ,moveY = True)

        cmds.scale(pyramid_height,pyramid_height, scaleXZ = True)

        pyramid_height = pyramid_height - 1

        

#########ADDING A BUTTON###########################################################

    

window = cmds.window( title="Create a pyramid", iconName='Pyramid', widthHeight=(200, 55) )

cmds.columnLayout( adjustableColumn=True )

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

slider = cmds.intSlider( min=-100, max=100, value=0, step=1 )

cmds.button( label='Create Pyramid',command = "Pyramid_custom(slider)"  )

cmds.showWindow( window )

   

                

###################################################################################


this code tells you how to add an integer slider to a button in python, which allows you to change a value from the slider and input the value into a button which then creates a pyramid based on the input size the user puts in.

the pieces of code that are highlighted in bold are the areas which i have added code of modified code in order to add the slider and make it functional.

Leave a comment

Log in with itch.io to leave a comment.