Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How can i get menuItems parent?

How can i get menuItems parent?

Anonymous
Not applicable
844 Views
2 Replies
Message 1 of 3

How can i get menuItems parent?

Anonymous
Not applicable

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?)

 

 

0 Likes
845 Views
2 Replies
Replies (2)
Message 2 of 3

lee.dunham
Collaborator
Collaborator

You could probably use the collection flag to query the radioButtonCollection it belongs to (and then get the current state).

To address the issue you're experiencing, the parent flag isn't query-able (no Q next to it in documentation), which would explain your error.

0 Likes
Message 3 of 3

Anonymous
Not applicable

hi lee

I could get radioMenuItemCollection, but the element does not have "select" or  "collectionItemArray" radioCollection have.

0 Likes