adding a menuitem after whole UI created


menuItem -label “BlahBlah” -c “doBlah” -parent mainEditMenu;

if I put this code to usersetup.mel
it gives error. because maineditmenu does not still created.

is it possible to run a script after maya is really opened and whole UI created ?

I dont want to manually built like this code :buildEditMenu mainEditMenu

I just need to run my script after whole maya opened and all UI items are really created and queryable
should I use evaldeferred instead source my script in usersetup.mel ?


Try using the “evalDeferred” command to delay execution of your command.


evaldeferred didnt help

when I manually source my script after maya opened. everything works correctly.
but If I put source command line to usersetup.mel it attempts to create menuitems before the current menu build operations completed even if I use evaldeferred or not.

here is the code :
its not possible to run it automatically.
if you run it in maya after mayaUI opened. it works
if you put it anywhere with or without evaldeferred it doesnt work correctly.because mayaUI wasnt created while maya executes usersetup.mel

here is sample code :

 string $menu = "mainPolygonsEditMeshMenu"; 

menuItem -label "BlahBlah" -c "doBlah" -ia invertSelectionItem -parent mainEditMenu;


Is the mel code in the file you’re sourcing wrapped in a global proc?
If not, create a global proc from your code. Then from your userSetup.mel, source the mel file (without the evalDeferred), then run the global proc command through the evalDeferred.

Hope that helps.


not helped.

this is what line I have in usersetup.mel


and this is newone.mel file with just two line :

global proc newone()
string $menu = "mainPolygonsEditMeshMenu";
menuItem -label "BlahBlah" -c "doBlah" -ia invertSelectionItem -parent mainEditMenu;

no luck.

here is another example script.[color=blue][color=blue]maya[/color][/color]/downloads/mel_scripts/interface_display/5155.html

this is not possible to run correctly.
because it destroys main edit menu (“as you see in snapshot”).
runnig code only works correctly if I run manually after maya opened.but it is useless way.

run it with evaldeferred or not in usersetup.
it wont work correctly.because of [color=blue][color=blue]maya[/color][/color] seems running usersetup.mel before whole mayaUI created.



in userSetup.mel append:

// begin cly_BlahBlahMenuBuild at startUp template
string $cmd = "menuItem -label \"BlahBlah\" -c ( \"print [\\\"doBlah\\\"\](" ) -ia invertSelectionItem -parent mainEditMenu;";
-runOnce true // scriptjob dies on execution " BlahBlah menuItem will survive new scenes and menuMode changes"
-event "SceneOpened" 
// end template

hope that helps


thanks clay for interest.I thought same as you .but I didnt tried since you post.
but still no luck
didnt helped.
same result as snapshot.

“idle” also didnt help.
there is only one way to run code manually after maya opened.

this is very weird.
it seems there is no good way to achieve this.maybe I must modify core mel files. but its not appropriate way.


Don’t do that claudio :wink:

The start up code i posted does werk in userSetup.mel ( tested in maya 2008 and 8.5 ) and
I do not have a “magic” version of Maya.

[left]That means your solution is close.[/left]

my best guesses:[left]1. in attempting this menu, u now have code that is conflicting with mine either in userSetup.mel or in another mel u have created recently. ( temporarily disable any edit menu code u made that u know of )

[left]2. You have an error in your userSetp.mel preventing the scriptJob from being created[/left]

[left]3. You have “another” userSetup.mel in one of many possible script directories that is overiding the one with the working code[/left]


[left]2 and 3 are the easiest to check for,[/left]
[left] [/left]
[left]Test the userSetup.mel file you are working with by appending at the VERY BOTTOM:[/left]
[left]this code:[/left]

[left]print " IS IT WORKING ?????????????????????????????????????


[left]after startup open the script Editor if you can’t find that print. then u will n\know the problem is 2 or 3[/left]


ofsure they works for earlier versions but not in 2009.

finally I found only a solution.
to built up my own stufs in mainmenu on top UI instead of inserting to standart menus.

any my afraid has become.thread closed :L


Never say die!

Maya 2009? great! so… perhaps menus are created differently?
If we echo all commands we find that this is indeed the case.
The edit is built dynamically when first accessed:


and then only updated on subsequent updates:


studying the actual mel in question we find that buildEditMenu.mel executes both
code examples as a post menu command. The benifit of these -postMenuCommand 's is the dynamic build of recent commands( history )… nice

The userSetup code now uses it as a “post” post menu command thusly:

// begin cly_BlahBlahMenuBuild at startUp template
// Maya 2009 friendly
string $cmd = "buildEditMenu(\"MayaWindow|mainEditMenu\"); menuItem -label \"BlahBlah\" -c ( \"print [\\\"doBlah\\\"\](" ) -ia \"invertSelectionItem\" -parent mainEditMenu;";
-runOnce true // scriptjob dies on execution " BlahBlah menuItem will survive new scenes and menuMode changes"
-event "SceneOpened" 
// end template

VOILA! champagne…


Since he didn’t respond, I’m gonna step in and thank you. Appreciate you taking the time to answer and showing me and others less knowledgeable how it’s done. Appreciate it!
Keep it up.


I am appricating your problem solving attempts.But it doesnt work too.

(Just Joking ! - Now Tried the last solution -it works !)

I was so ensure that its not possible.
thank you soo much


the scriptJob doesnt working too.
(it works for standart menus only)

because the spesific menus does not creating in maya startup.
for example try to add an menu under Polygon>Mesh

standart menus under Mesh getting lose


because menu mode menus aren’t created at startup… let’s pre-build them. fer instance polygon menu set’s “mesh”:
( insert Blah Blah at the end of “mesh” )

// build mesh menu in userSetup.mel for 2009 with:
//PolygonsMeshMenu MayaWindow|mainPolygonsMeshMenu; 
// begin cly_BlahBlahMenuBuild at startUp template
string $cmd = "PolygonsMeshMenu MayaWindow|mainPolygonsMeshMenu; menuItem -label \"BlahBlah\" -c ( \"print [\\\"doBlah\\\"\](" ) -parent mainPolygonsMeshMenu;";
-runOnce true // scriptjob dies on execution " BlahBlah menuItem will survive new scenes and menuMode changes"
-event "SceneOpened" 
// end template

To assure menu is actually built at startup… in preferences:under interface

choose the Animation “menu set”

Now when we start up…

The Animation Menu mode will be present.
Switch to the polygon menu mode set and Voila’ under mesh we do find our beloved Blah Blah menuItem built in the mesh menu.



Since Maya2009 it doesn’t matter what you do to get items into the main menus at boot, none will work unless you evoke a build on the menu itself. One of the reasons that 2009 boots so much faster is that they don’t build any menus at boot time, so any calls to add into them will fail.

More over if you try adding into the menus during boot, then go to file menu, the menu won’t actually work! (you’ll just get your contents and none of the Maya calls) Not only do they build the menus only when you first click on them, they also check the contents size. It took ages for us to track this one down, for weeks we had nothing in the fileMenus except 2 internal additions.

buildFileMenu is the call we use to force build the fileMenu, there’s bound to be a matching call to force build the editMenu, then you can just add items at will

hope that helps.


“buildEditMenu” like posted before


frpm the highend3d listserve: to maya
show details 11:36 AM (10 hours ago) Reply

Hi Andy,
> Adding menu items to the File menu in the userSetup.mel deosn’t seem to work in 2009. The menu seems to be created later. Has anyone had any luck trying to hack the menus?
This is what we do in a startup script:
if (!about -b && substring ((string)about ("-v"), 1, 4) == “2009”)
catch(buildFileMenu); // This is required in Maya 2009 to let procedures add new menuItems without overriding the originals.
evalDeferred -lp “procThatBuildsMenus”;
Mailed by Highend3D Web Interface


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.