Hi All,
I am still brushing up on Python and thought I would share another example of some code I have created.
This code creates a cube but only if you check the check box in the User Interface.
Hope this helps in your projects too 🙂
import maya.cmds as cmds
#Creates variable to indecate the check box status. 1=Checked 0=Not Checked.
cubeNum = 0
#Creates Button funtion.
def defaultButtonPush(*args):
#The Print checks if button is pushed and what is the check box status.
print "Button is pushed."
print cubeNum
#Check box argument finds the status of the variable and determines what to do.
#Eather create a cube or display a error dialog box.
if cubeNum == 1:
print "Cube Creation suessful"
cmds.polyCube()
else:
cmds.confirmDialog(t="Error",m="Cube will not be created."+ 'n' + 'Please check the box to create a cube.')
#Creates ui.
cmds.window( title="Toms Cube maker",wh=(350,250) )
cmds.columnLayout( adjustableColumn=True )
#Creates Button.
cmds.button( label='Execute', command=defaultButtonPush ,align='left' )
#Creates check box.
#In the onCommand Script (onc) and offCommand Script (ofc) flags all commands must be made in between double quotes.
cmds.checkBox(label='Cube',value=False,align='left',onc="cubeNum = 1", ofc="cubeNum = 0")
cmds.showWindow()
One Response to Python Check Boxes