Search code examples
pythonradio-buttonmayapopupmenumaya-api

Cmds.radioMenuItemCollection - get selected


Hey all I am trying to get the name of the selected menuItem(radioButton) in a popupMenu. I know in cmds.radioCollection they have a flag called "select" but for cmds.radioMenuItemCollection the flag select doesn't exist. How can I get the name of the selected option


Solution

  • It looks like ADSK forgot to expose all the controls on that one! It doesn't report as a regular radioCollection. so the only workaround is something like this:

    cmds.window( menuBar=True )
    q = cmds.menu( label='Position' )
    r = cmds.radioMenuItemCollection()
    x =cmds.menuItem( label='Top', radioButton=False )
    y = cmds.menuItem( label='Middle', radioButton=False )
    z = cmds.menuItem( label='Bottom', radioButton=True )
    cmds.showWindow()
    
    selected = max ([t if cmds.menuItem(t, q=True, rb=True) else None for t in  (x,y,z)])