Message 1 of 3
How can i get menuItems parent?
Not applicable
02-02-2019
05:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to create custom menu on main window menubar, and radio button on it.
I don't know how to get the status of radio button on callback function, so I tried to get parent menu from menu item, but I got stuck because querying parent on menu item is failed.
import maya.cmds as mc import maya.mel as mel def checkStatus(menuItem) :
# below statement failed with
# Error: RuntimeError: file <maya console> line 6: No flags found that can be queried. parent = mc.menuItem(menuItem, query=True, parent=True) collection = mc.menuItem(menuItem, query=True, collection=True) for item in mc.menu(parent, query=True, itemArray=True) : if mc.menuItem(menuItem, query=True, isRadioButton=True) and mc.menuItem(item, query=True, collection=True) == collection : if mc.menuItem(item, query=True, radioButton=True) : break else : print('could not find ON status radio button.') print('%s : %s' % (collection, mc.menuItem(item, query=True, label=True))) gMainWindow = mel.eval('$tmpVar = $gMainWindow') menuId = 'Test_Menu' if mc.menu(menuId, exists=True) : mc.menu(menuId, edit=True, deleteAllItems=True) else : mc.menu(menuId, label='My Menu', parent=gMainWindow) mc.menuItem('divider1', divider=True, dividerLabel='like apple?', parent=menuId) collection1 = 'collectionYesNo' mc.radioMenuItemCollection(collection1, parent=menuId) mc.menuItem('menu_item1', label='Yes', radioButton=True, command='checkStatus("menu_item1")', sourceType='python', parent=menuId) mc.menuItem('menu_item2', label='No', radioButton=False, command='checkStatus("menu_item2")', sourceType='python', parent=menuId) mc.menuItem('divider2', divider=True, dividerLabel='Most like?', parent=menuId) collection2 = 'collectionChoiceOne' mc.radioMenuItemCollection(collection2, parent=menuId) mc.menuItem('menu_item3', label='Tennis', radioButton=True, command='checkStatus("menu_item3")', sourceType='python', parent=menuId) mc.menuItem('menu_item4', label='Soccor', radioButton=False, command='checkStatus("menu_item4")', sourceType='python', parent=menuId) mc.menuItem('menu_item5', label='Baseball', radioButton=False, command='checkStatus("menu_item5")', sourceType='python', parent=menuId) mc.menuItem('menu_item6', label='Valleyball', radioButton=False, command='checkStatus("menu_item6")', sourceType='python', parent=menuId)
How can i get parent UI ? (or how can i get radiobutton menuItem status?)