Maya Python – Querying a Radio Button

Hi & happy new year. To start off I’m going to add some Maya – Python snippets here that I find useful, especially to a beginner. This is for a basic radio button and accessing the state of it.

import maya.cmds as cmds
 
def QueryResults(grp):
	grpResults = cmds.radioButtonGrp(grp,query=True, select=True) #select will return integer based on radio selection
	if grpResults is 1:
		side = 'LEFT'
	if grpResults is 2:
		side = 'RIGHT'
	print ('Congrats! You have picked ' + side + '.')
 
def Main():
	#GUI -----------------------------
	if cmds.window('testQueryRadioButtonWindow', exists=True):
		cmds.deleteUI('testQueryRadioButtonWindow', window=True) 
 
	cmds.window('testQueryRadioButtonWindow', title='testQueryRadioButton', h=200, w=400)
	cmds.columnLayout()
 
	cmds.rowLayout(numberOfColumns = 1)
	myRadioGrp = cmds.radioButtonGrp( label='Choose side:', labelArray2=['LEFT', 'RIGHT'], select=1, numberOfRadioButtons=2 )
	cmds.setParent('..')
 
	cmds.rowLayout(numberOfColumns = 2)
	cmds.button(bgc=(0,1,.25), label='Query', command= lambda *args: QueryResults(myRadioGrp))
	cmds.setParent('..')
 
	cmds.setParent('..')
	cmds.showWindow('testQueryRadioButtonWindow')
 
Main()

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>