PDA

View Full Version : Python optionMenuGrp problem


tcomputerchip
11-12-2011, 08:03 AM
I posted this on "area" thinking people actually use autodesk's forumns (silly me). In any case, I hope someone can read this and tell me what I might be doing wrong:



I have some code that creates the main window. In that window I have an optionMenuGrp, I want to update the optionMenuGrp after the window is created (and later when a user selects some options). So the "update_menu" is VERY important that it works.

Do I have to defer evaulation? Or am I missing some command? I get the error:


# Error: Menu Item's menu not found.
# Traceback (most recent call last):
# File "<maya console>", line 39, in <module>
# File "<maya console>", line 29, in __init__
# File "<maya console>", line 37, in update_menu
# RuntimeError: Menu Item's menu not found. #


When I try to simply update the menuItem, it says it don't exist, yet I am giving it its parent with "p=".

Here is a example code, no menu items ever get update when in a method:

from maya import cmds

class myui:
def __init__(self):
windowname = "MyWindow92"
self.win = cmds.window(windowname, title='My UI', iconName=windowname, widthHeight=(650,250))
self.layout = cmds.columnLayout()
menuobj = cmds.optionMenuGrp("optionmenu", label='My Options:')

# add some default menu item
cmds.menuItem(label="Select Item")
# now lets try to add some more options via a function

try:
self.update_menu("test-a", menuobj)
except Exception, err:
print "ERROR: %s" % err
print "FAILED TEST-A"
self.optionsmenu2 = cmds.optionMenuGrp("optionmenu-2", label='My 2nd Options')

try:
self.update_menu("test-b", menuobj)
except Exception, err:
print "ERROR: %s" % err
print "FAILED TEST-B"

cmds.showWindow(self.win)
try:
self.update_menu("test-c", menuobj)
except Exception, err:
print "ERROR: %s" % err
print "FAILED TEST-C"

#

def update_menu(self, mytext, menuobj):
cmds.menuItem(label=mytext, p=menuobj)

myui()

NaughtyNathan
11-12-2011, 12:00 PM
optionMenuGrp is a layout control, not a menu and you cannot add meuItems to a layout. You need to find out the name of the actual optionMenu control under the optionMenuGrp and add your items to that. for example:
def update_menu(self, mytext, menuobj):
menu = cmds.layout(menuobj, q=1, ca=1)[-1] # get the last item, the optionMenu
cmds.menuItem(label=mytext, p=menu)
:nathaN

tcomputerchip
11-13-2011, 07:43 AM
Thank you, that did it. Was trying all sorts of things. Now I can load the settings on the fly.

The next part will be to delete everything in the list and re-add everything. I think I have some code that already does that.

CGTalk Moderation
11-13-2011, 07:43 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.