Python Checkbox question

Python Checkbox question

Anonymous
Not applicable
3,693 Views
3 Replies
Message 1 of 4

Python Checkbox question

Anonymous
Not applicable

Hey guys, so here is what I'm trying to do: select a shape via checkbox and hit execute, then create the shape of your choosing. Atleast in theory that is how it should work, in practice however: it just creates cylinders from the cylinder option and thats it, so if anyone wants to take a crack at it, here you go:

 

import maya.cmds as cmds

 

#Creates ui.

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

cmds.deleteUI(window)

 

window = cmds.window( title = "DS Shape Builder Demo", widthHeight=(300, 200) )

cmds.columnLayout(adjustableColumn=True)

 

#Creates variable to indecate the check box status. 1=Checked 0=Not Checked.

cubeNum = 0

cubeNum1 = 0

cubeNum2 = 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 sucessful"

cmds.polyCube()

else:

cmds.confirmDialog(t="Error",m="Cube will not be created."+ 'n' + 'Please check the box to create a cube.')

 

def defaultButtonPush(*args):

print "Button is pushed."

print cubeNum1

if cubeNum1 == 1:

print "Sphere Creation sucessful"

cmds.polySphere()

else:

cmds.confirmDialog(t="Error",m="Sphere will not be created."+ 'n' + 'Please check the box to create a Sphere.')

 

def defaultButtonPush(*args):

print "Button is pushed."

print cubeNum2

if cubeNum2 == 1:

print "Cylinder Creation sucessful"

cmds.polyCylinder()

else:

cmds.confirmDialog(t="Error",m="Cylinder will not be created."+ 'n' + 'Please check the box to create a Sphere.')

 

#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',onCommand="cubeNum = 1", offCommand="cubeNum = 0")

cmds.checkBox(label='Sphere',value=False,align='left',onCommand="cubeNum1 = 1", offCommand="cubeNum1 = 0")

cmds.checkBox(label='Cylinder',value=False,align='left',onCommand="cubeNum2 = 1", offCommand="cubeNum2 = 0")

#Creates Button.

cmds.button( label='Execute', command=defaultButtonPush ,align='left' )

 

cmds.showWindow()

0 Likes
Accepted solutions (1)
3,694 Views
3 Replies
Replies (3)
Message 2 of 4

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

Hi,

Try This....

import maya.cmds as cmds

if cmds.window(window1, exists =True):
    cmds.deleteUI(window1)

window1 = cmds.window(title = "DS Shape Builder Demo", widthHeight=(450, 200) )
cmds.rowColumnLayout( numberOfColumns=1 )
rsCheckSel = cmds.checkBoxGrp( numberOfCheckBoxes=3, label='Select Shape', labelArray3=['Cube', 'Sphere', 'Cylinder'] )
cmds.button( label='Create Shape', c = rsBuidShape)
cmds.showWindow(window1)

def rsBuidShape(self):
    if(cmds.checkBoxGrp(rsCheckSel,q=1,v1=1)):
        print "Button is pushed."
        cmds.polyCube()
        print "Cube Creation sucessful"
        
    if(cmds.checkBoxGrp(rsCheckSel,q=1,v2=1)):
        print "Button is pushed."
        cmds.polySphere()
        print "Sphere Creation sucessful"
        
    if(cmds.checkBoxGrp(rsCheckSel,q=1,v3=1)):
        print "Button is pushed."
        cmds.polyCylinder()
        print "Cylinder Creation sucessful"
0 Likes
Message 3 of 4

Anonymous
Not applicable

Awesome! That did the trick: thank you so much!

0 Likes
Message 4 of 4

rajasekaransurjen
Collaborator
Collaborator

You are welcome.

0 Likes