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!