Drop-down box Menu Items Command

Drop-down box Menu Items Command

Admiral.Pixel
Enthusiast Enthusiast
5,466 Views
1 Reply
Message 1 of 2

Drop-down box Menu Items Command

Admiral.Pixel
Enthusiast
Enthusiast

Hi all! How can I run commands on menuItems when selected? I was trying to make a def function but don't know how to properly execute it 

cmds.optionMenu(label='Pivot', changeCommand=pivotOrient)

cmds.menuItem( label='Object', )
cmds.menuItem( label='World')
cmds.menuItem( label='Component' )
cmds.menuItem( label='Normal' )

When I select "Object" the pivot orientation changes to "object", when I select "World," the pivot orientation changes to "world" and so on. I know that the feature is already in the Modeling Toolkit but I'm trying to make a custom-built and a simplified version of it. Thanks in advance.    Untitled.png

0 Likes
Accepted solutions (1)
5,467 Views
1 Reply
Reply (1)
Message 2 of 2

Roland.Reyer
Autodesk
Autodesk
Accepted solution

The function that you provide in the "changeCommand" option gets called when the user chooses another option in the dropdown.

 

The function has to find out what the new value is. For that it is a good idea to pass the name of the UI element so that the function can query the new value:

 

pivotMenu = optionMenu( label='Pivot')

optionMenu( pivotMenu, edit=1, changeCommand='pivotOrient( pivotMenu)')

 

Your function pivotOrient can now query the state of the menu pivotMenu and set the pivot accordingly.

0 Likes