PDA

View Full Version : adding a menuitem after whole UI created


claudiof
02-20-2009, 06:17 PM
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 ?

visualfx
02-20-2009, 07:04 PM
Try using the "evalDeferred" command to delay execution of your command.

claudiof
02-20-2009, 08:04 PM
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;

visualfx
02-20-2009, 09:07 PM
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.

claudiof
02-20-2009, 09:10 PM
not helped.

this is what line I have in usersetup.mel
evalDeferred("newone()");


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.
http://img21.imageshack.us/img21/5462/snap1sg7.jpg




okay.
here is another example script.

http://www.highend3d.com/maya/downloads/mel_scripts/interface_display/5155.html (http://www.highend3d.com/maya/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 maya seems running usersetup.mel before whole mayaUI created.

claydough
02-21-2009, 08:15 AM
here:

in userSetup.mel append:


// begin cly_BlahBlahMenuBuild at startUp template
{
string $cmd = "menuItem -label \"BlahBlah\" -c ( \"print \\\"doBlah\\\"\ (http://forums.cgsociety.org/)" ) -ia invertSelectionItem -parent mainEditMenu;";
scriptJob
-runOnce true // scriptjob dies on execution " BlahBlah menuItem will survive new scenes and menuMode changes"
-event "SceneOpened"
$cmd;
}
// end template



hope that helps

claudiof
02-21-2009, 12:37 PM
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.

claydough
02-21-2009, 03:45 PM
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 ;)

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.

http://farm4.static.flickr.com/3388/3297058103_f1a3310cb8.jpg

That means your solution is close.






my best guesses: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 )



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

3. You have "another" userSetup.mel in one of many possible script directories that is overiding the one with the working code



2 and 3 are the easiest to check for,,,

Test the userSetup.mel file you are working with by appending at the VERY BOTTOM:
this code:

print " IS IT WORKING ?????????????????????????????????????\n";


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

claudiof
02-21-2009, 07:04 PM
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

claydough
02-21-2009, 09:06 PM
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

Quiter!:scream:
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:
buildEditMenu("MayaWindow|mainEditMenu");

and then only updated on subsequent updates:
editMenuUpdate("MayaWindow|mainEditMenu");

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\\\"\ (http://forums.cgsociety.org/)" ) -ia \"invertSelectionItem\" -parent mainEditMenu;";
scriptJob
-runOnce true // scriptjob dies on execution " BlahBlah menuItem will survive new scenes and menuMode changes"
-event "SceneOpened"
$cmd;
}
// end template


VOILA! champagne...
:beer:

Geuse
02-25-2009, 06:50 PM
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.

claudiof
02-27-2009, 01:54 PM
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

claudiof
03-01-2009, 05:12 PM
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

claydough
03-02-2009, 05:56 AM
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\\\"\ (http://forums.cgsociety.org/)" ) -parent mainPolygonsMeshMenu;";
scriptJob
-runOnce true // scriptjob dies on execution " BlahBlah menuItem will survive new scenes and menuMode changes"
-event "SceneOpened"
$cmd;
}
// 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.



.:wavey:

Mark-J
03-02-2009, 08:03 AM
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.

claydough
03-02-2009, 08:26 AM
`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


"buildEditMenu" like posted before

claydough
03-20-2009, 01:50 AM
frpm the highend3d listserve:



szabolcs@impresszio.hu 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";
Cheers,
Szabolcs
Mailed by Highend3D Web Interface

CGTalk Moderation
03-20-2009, 01:50 AM
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.