tcomputerchip
11-12-2011, 07: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()
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()
