Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / optionMenuGrp and python
  RSS 2.0 ATOM  

optionMenuGrp and python
Rate this thread
 
61881
 
Permlink of this thread  
avatar
  • Total Posts: 11
  • Joined: 22 August 2006 10:40 PM

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(windownametitle='My UI'iconName=windownamewidthHeight=(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 Exceptionerr:
      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 Exceptionerr:
      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(selfmytextmenuobj):
    
cmds.menuItem(label=mytextp=menuobj)

myui()


Replies: 1
/img/forum/dark/default_avatar.png

I should note, uncomment the “try” block and indent self.update_menu("test-c", menuobj) line 2 spaces to get the window to show, however, no menu items after the first menu item get added to the optionGroup

Author: tcomputerchip

Replied: 11 November 2011 02:07 PM  
avatar

Found a fix. The problem is that optionMenuGrp is a laytout and not a control.

I have to do this:

def update_menu(selfmytextmenuobjgrp):
    
menu cmds.layout(menuojgrpq=Trueca=True)[-1]
    cmds
.menuItem(label=mytextp=menuobjgrp)


Replies: 0