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.

Python - How to change selection in optionMenu

Python - How to change selection in optionMenu

Craig_Lamorte
Advocate Advocate
1,867 Views
3 Replies
Message 1 of 4

Python - How to change selection in optionMenu

Craig_Lamorte
Advocate
Advocate

Hi, I am trying to figure out how to change the menuItem selction in an optionMenu but am unable to figure it out.

 

mymenu = cmds.optionMenu(label ='select type', cc=selecttypecallback)

cmds.menuItem(parent=mymenu, label='selection1')

cmds.menuItem(parent=mymenu, label='selection2')

 

Now how do I call call mymenu again and check the current selected menuItem to the one i choose?

0 Likes
1,868 Views
3 Replies
Replies (3)
Message 2 of 4

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Please look at the optionMenu document. It could be used like below.

 

import maya.cmds as cmds

def printNewMenuItem( item ):
	print item

window = cmds.window()
cmds.columnLayout()
#Please store the menu when creating it
opmenu = cmds.optionMenu( label='Colors', changeCommand=printNewMenuItem )
cmds.menuItem( label='Yellow' )
cmds.menuItem( label='Purple' )
cmds.menuItem( label='Orange' )
cmds.showWindow( window )

#Use optionMenu command
cmds.optionMenu(opmenu, e=True, sl=3)
print cmds.optionMenu(opmenu, q=True, value=True) , cmds.optionMenu(opmenu, q=True, sl=True)

 

Yours,

Li

0 Likes
Message 3 of 4

Craig_Lamorte
Advocate
Advocate

I did look at the documentation and everything i tried couldn't get it working.  I did try what you did in your example and everytime i try to set the selection it says value out of range.  If I print what the selection and value are it will correctly print it, but it wont let me set it.

0 Likes
Message 4 of 4

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Can you tell me your Maya version and give me a sample how you are using this command? My code snippet seems working fine on Maya 2018 Update 1.

 

Yours,

Li

0 Likes