you need to pass the checkbox's name into the call to checkBox in GetSelectedNodes:
def GetSelectedNodes(self,*args):
cal = cmds.checkBox(self.xAxis,q = True, v = True)
print cal
Question
I'm trying to get the state of a checkbox in a maya UI using python. I was wondering if someone would help me. currently when the user hits the Distribute button, it calls a function which should print the true/false state of the 'x' checkbox.
import maya.cmds as cmds
class createMyLayoutCls(object):
def __init__(self, *args):
pass
def show(self):
self.createMyLayout()
def createMyLayout(self):
#check to see if our window exists
if cmds.window('utility', exists = True):
cmds.deleteUI('utility')
# create our window
self.window = cmds.window('utility', widthHeight = (200, 200), title = 'Distribute', resizeToFitChildren=1, sizeable = False)
cmds.setParent(menu=True)
# create a main layout
mainLayout = cmds.columnLayout(w = 200, h = 200, cw = 10, rs = 8, co = ['both',2])
# X Control
self.xAxis = cmds.checkBox('X')
# Distribute Button
btnDistribute = cmds.button(label = 'Distribute', width = 200, height = 40, c = self.GetSelectedNodes)
# show window
cmds.showWindow(self.window)
def GetSelectedNodes(self,*args):
cal = cmds.checkBox(self['X'],q = True, v = True)
print cal
b_cls = createMyLayoutCls()
b_cls.show()
Solution
you need to pass the checkbox's name into the call to checkBox in GetSelectedNodes:
def GetSelectedNodes(self,*args):
cal = cmds.checkBox(self.xAxis,q = True, v = True)
print cal