# optionMenu menuItem edits?

**URL:** https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467
**Category:** Maya
**Tags:** mel
**Created:** [April 5, 2004, 3:30am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467 "2004-04-05T03:30:38Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![chris-mills](https://forum.highend3d.com/user_avatar/forum.highend3d.com/chris-mills/32/327_2.png) [@chris-mills](https://forum.highend3d.com/u/chris-mills)
#### Post date: [April 5, 2004, 3:30am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/1 "2004-04-05T03:30:38Z")

</div>

Is there any way to use MEL to edit existing menuItems in an optionMenu in a custom gui? I can not find any reference material on how to do this.

Thanks.

---

<div class="post-metadata">

### Author: ![macaronikazoo](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@macaronikazoo](https://forum.highend3d.com/u/macaronikazoo)
#### Post date: [April 5, 2004, 7:32am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/2 "2004-04-05T07:32:41Z")

</div>

an entry in an optionMenu is a menuItem UI control. so its just a normal UI item, and you edit it just as you would any other UI control.

---

<div class="post-metadata">

### Author: ![chris-mills](https://forum.highend3d.com/user_avatar/forum.highend3d.com/chris-mills/32/327_2.png) [@chris-mills](https://forum.highend3d.com/u/chris-mills)
#### Post date: [April 5, 2004, 9:34am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/3 "2004-04-05T09:34:21Z")

</div>

Uh, right...

Let's say you have a simple optionMenu that you are calling:

string $window = `window`;  
 columnLayout;  
 optionMenu -label "Colors";  
 menuItem -label "Yellow";  
 menuItem -label "Purple";  
 menuItem -label "Orange";  
 showWindow $window;

And you want to programatically change the label for "Orange" to some other word. How would you do it? I can not find any sytactical references to how one calls a menuItem label under an optionMenu to edit it. Any light shed on this would be appreciated. Thanks.

---

<div class="post-metadata">

### Author: ![naughty](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/35a633/32.png) [@naughty](https://forum.highend3d.com/u/naughty)
#### Post date: [April 5, 2004, 10:19am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/4 "2004-04-05T10:19:05Z")

</div>

I think your problem is that you aren't naming any of your controls, so you can't (easily) refer back to them. If you do something like this:

menuItem -label "Orange" orangeItem;

(which is naming this control "orangeItem") you can then do this later on:

menuItem -edit -label "Purple" orangeItem;

and your menuItem label should now read "Purple". You might have to name ALL your controls that parent this menuItem and refer to it in it's "pathed" position but I think the easy example above will probably work for you.

If you want to be really clever, you could do it this way:

string $orangeItem = `menuItem -label "Orange"`;

then refer to it like this:

menuItem -edit -label "Purple" $orangeItem;

Unfortunately, I don't have Maya to hand to check this and it's been a while.. ![](http://www2.highendnet.com/forums/icons/wink.gif) but the above should be what you want to know.

:nathaN

---

<div class="post-metadata">

### Author: ![chris-mills](https://forum.highend3d.com/user_avatar/forum.highend3d.com/chris-mills/32/327_2.png) [@chris-mills](https://forum.highend3d.com/u/chris-mills)
#### Post date: [April 5, 2004, 10:25am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/5 "2004-04-05T10:25:35Z")

</div>

Yah - just as I was discovering the same on my own your post came through. Here's my solution:  
string $window = `window`;

columnLayout;

string $colors = `optionMenuGrp -label "Colors"`;

menuItem -label "Yellow";

menuItem -label "Purple";

menuItem -label "Orange";

showWindow $window;

menuItem -parent ($colors + "|OptionMenu") -e -label "Blue" "Orange";

I really like your appending the menu name on the end - that should be just the thing - that's the bit that seems to bite me on the ass when I'm having trouble - that and v5's "wonderous" documentation.

Thanks!

---

<div class="post-metadata">

### Author: ![chris-mills](https://forum.highend3d.com/user_avatar/forum.highend3d.com/chris-mills/32/327_2.png) [@chris-mills](https://forum.highend3d.com/u/chris-mills)
#### Post date: [April 5, 2004, 10:40am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/6 "2004-04-05T10:40:10Z")

</div>

For posterity's sake: don't forget the closing inverted comma on the string eval:

string $orangeItem = `menuItem -label "Orange"`;

---

<div class="post-metadata">

### Author: ![naughty](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/35a633/32.png) [@naughty](https://forum.highend3d.com/u/naughty)
#### Post date: [April 5, 2004, 10:53am UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/7 "2004-04-05T10:53:06Z")

</div>

mistake? what mistake?? ![](http://www2.highendnet.com/forums/icons/wink.gif) heh, nice spot, thanks..

---

<div class="post-metadata">

### Author: ![tscott1213](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/f475e1/32.png) [@tscott1213](https://forum.highend3d.com/u/tscott1213)
#### Post date: [July 13, 2005, 11:06pm UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/8 "2005-07-13T23:06:00Z")

</div>

Is there a way to delete a menuitem from a group as well? I have a optionMenuGrp with items that change based on what is in the scene.

Thanks

---

<div class="post-metadata">

### Author: ![tscott1213](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/t/f475e1/32.png) [@tscott1213](https://forum.highend3d.com/u/tscott1213)
#### Post date: [July 13, 2005, 11:16pm UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/9 "2005-07-13T23:16:36Z")

</div>

ahh...

deleteUI does the trick.

---

<div class="post-metadata">

### Author: ![fhaab](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/bb73d2/32.png) [@fhaab](https://forum.highend3d.com/u/fhaab)
#### Post date: [April 10, 2006, 3:54pm UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/10 "2006-04-10T15:54:02Z")

</div>

Another question - is there a simple way to clear out all the entries in an optionMenu besides keeping an array of all the menu items and deleting them?

So, for example, let's say I have an optionMenuGrp that lists all the textures. I can't have the system call my functions to add a new menu item each time a texture is created, so let's say I have a "refresh" button on my UI that calls a function that clears out the whole menu and then adds on all the textures.

Is there any way to do this with keeping a global array of all the items added?

A function like "optionMenuGrp -e -clear texture\_menu" would be great, but doesn't exist. If there was some way to do something like listing all the children of the texture\_menu and then deleting them, that'd be great, too. But I can't seem to find a way to do it.

I'd like to add a function like this to my toolbox for future use:

clear\_menu("texture\_menu")

there must be some generic way to do this.

---

<div class="post-metadata">

### Author: ![naughty](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/35a633/32.png) [@naughty](https://forum.highend3d.com/u/naughty)
#### Post date: [April 10, 2006, 4:12pm UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/11 "2006-04-10T16:12:01Z")

</div>

you could always just do something like:

CODE  
deleteUI `optionMenuGrp -q -ill texture\_menu`;

it's a bit brutish, but it works.

---

<div class="post-metadata">

### Author: ![fhaab](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/bb73d2/32.png) [@fhaab](https://forum.highend3d.com/u/fhaab)
#### Post date: [April 10, 2006, 5:01pm UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/12 "2006-04-10T17:01:27Z")

</div>

Thanks! Figured it out, came here to post my solution, and saw yours. Works like a charm.

---

<div class="post-metadata">

### Author: ![fhaab](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/f/bb73d2/32.png) [@fhaab](https://forum.highend3d.com/u/fhaab)
#### Post date: [April 11, 2006, 1:52pm UTC](https://forum.highend3d.com/t/optionmenu-menuitem-edits/4467/13 "2006-04-11T13:52:16Z")

</div>

Ok, here I go again... my UI has several option menus, some of which need to be updated.

Something like meesto suggested:

menuItem -parent ($colors + "|OptionMenu") -e -label "Blue" "Orange";

Doesn't work for me:

$tmenu = `optionMenuGrp -label "Texture:" textureMenu`;

//  
// later, after much code and other menus have been built  
//

// clear out the menu...  
// deleteUI `optionMenuGrp -q -ill $tmenu`; - doesn't work for some reason.  
//  
string $items[] = `optionMenuGrp -q -ill $tmenu`;  
string $scan;  
for ($scan in $items) deleteUI $scan;

// rebuild with new textures:  
$items = `ls -textures`;  
$tmenu = ($tmenu + "|optionMenu");  
for ($scan in $items) menuItem -l $scan -parent $tmenu;

This simply hasn't worked for me... it keeps complaining that "...|textureMenu|optionMenu" (the ellipses for abbreviation only, it contains the full path) doesn't exist...

Well, yes, it exists - but I think the problem is that it's not a menu, which is what menuItem is expecting as a parameter for "-parent". This is another case of MEL and Maya being object based, NOT object oriented. If it were truly object oriented, optionMenu would be a sub-class of of Menu, and through polymorphism would be an acceptable object where a menu is required.

Ok... ultimately, my brute force solution is as follows:

formLayout textureForm  
optionMenuGrp -label "Texture:" textureMenu;  
setParent ..

//  
// later on...  
//

deleteUI textureMenu;  
optionMenuGrp -label "Texture:" -parent textureForm textureMenu;  
$items = `ls -textures`;  
$tmenu = ($tmenu + "|optionMenu");  
for ($scan in $items) menuItem -l $scan -parent $tmenu;

By keeping it in it's own little form, I don't have a placement problem. Hey, I could make it worse... I could delete the entire UI and just rebuild it every time some action occurs. There's got to be a better way!
