Checkboxes deselecting other checkboxes

236 views
Skip to first unread message

James Kim

unread,
Dec 24, 2018, 5:03:55 PM12/24/18
to Python Programming for Autodesk Maya
Hi,

I am building a ui an I am using checkboxes to enable sliders. Currently selecting and deselecting checkboxes enables and disables my sliders which is all well and good but I am trying to get it so when I select a checkbox it disables all other checkboxes. I have the checkbox's command set to a different function which i use to to enable and disable the corresponding sliders. I tried using an if statement but it gives me an error," Error: RuntimeError: file <maya console> line 38: Object 'False' not found." 
Here is my code so far

class sliderWindow():

    def __init__(self):
        self.name = 'windtest'
        self.size = [500, 500]

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

    def windMain(self):

        main = cmds.window(self.name, widthHeight=self.size,sizeable=True)
        cmds.columnLayout()

        self.rBtn = cmds.checkBox(label='test1', enable=True)
        self.rLayout = cmds.rowLayout(nc = 3,enable=False)

        self.slider1 = cmds.floatSliderGrp(label = 'TestS1', field = True, min = 0.000, max = 1.000, value = 0.500, step = 0.001)
        cmds.setParent('..')
        cmds.checkBox(self.rBtn, e= True,cc=partial(self.changeBox,self.rLayout))



        self.gBtn = cmds.checkBox(label='test2', enable=True)
        self.gLayout = cmds.rowLayout(nc=3,enable=False)
        self.slider2 = cmds.floatSliderGrp(label='testS2', field=True, min=0.000, max=1.000, value=0.500, step=0.001)
        cmds.setParent('..')
        cmds.checkBox(self.gBtn, e=True, cc=partial(self.changeBox, self.gLayout))



        cmds.showWindow(main)


    def changeBox(self,widget,*args):
   
        if hasattr(self, 'currentState'):
            self.currentState = cmds.rowLayout(self.currentState,q=True,enable=False)
        
        self.currentState = cmds.rowLayout(widget,q=True,enable=True)
        cmds.rowLayout(widget,e=True,enable=(1-self.currentState))

any help is appreciated. Thank you!









Justin Israel

unread,
Dec 24, 2018, 5:56:15 PM12/24/18
to python_in...@googlegroups.com
I don't know which line is 38. It would help if you shared this code as a pastebin in the future. But I think it's those last lines where you are passing a bool return value as if it were the layout name 

 if hasattr(self, 'currentState'):
    self.currentState = cmds.rowLayout(self.currentState,q=True,enable=False)

After you query if it's true or false it is no longer a string. I think you meant to pass a layout name. 



any help is appreciated. Thank you!









--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d2e2e651-0459-4214-8722-4c972f521cff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas Combecave

unread,
Dec 25, 2018, 2:09:49 AM12/25/18
to python_in...@googlegroups.com
Hi,
If you don't need more than 4 checkBoxes, there is the checkboxGrp command. It manages the checkboxes for you so you only have one checkbox active.
Otherwise, about your code, I have no maya access right now, but maybe your error is due to
querying currentState (which is a bool?)  instead of widget:
if hasattr(self, 'currentState'):
    self.currentState = cmds.rowLayout(widget,q=True,enable=False)

Also, you can use kwargs when you build a command with partial; It helps disambiguate the arguments given by the caller:
cmds.checkBox(self.rBtn, e= True,cc=partial(self.changeBox,layout=self.rLayout))
def changeBox(self,layout=None,*args):
     if not layout:
            return 
 etc...

Reply all
Reply to author
Forward
0 new messages