Another set of newbie questions....

55 views
Skip to first unread message

Tim Crowson

unread,
Apr 21, 2014, 11:49:30 AM4/21/14
to python_in...@googlegroups.com
I've got another set of questions here as I try to wrap my head around how Maya does things. I'm sure these are fairly mundane things in the end...

1. I know how to create my own custom menu at launch via userSetup.py, but I'm having trouble understanding how I would do this instead via a distributed plugin. The docs I've been looking at for custom commands, for example, are clear about what's necessary for Maya to recognize a registered command, but I don't see how to 'register' a custom menu. I tried to cheat my way around it by placing my buildMenu() code inside my custom command's initializePlugin() function, but that failed. I've seen one or two partial examples of a registerUI() method I can call, but I can't find any solid documentation on this. Anyway... just looking for some tips there on moving my custom menu out of the userSetup and into a shared plugin on the network.

2. Is it possible to have a custom plugin auto-load without requiring the user to explicitly check the option to auto-load it in the Plugin Manager?

3. Maya 2015 seems to take much longer than 2014 to shutdown. Is it just me or is something really different here?

Thanks again for any help!

-Tim Crowson
Magnetic Dreams

Tony Barbieri

unread,
Apr 21, 2014, 4:01:02 PM4/21/14
to python_in...@googlegroups.com
Hey Tim,

1. I know how to create my own custom menu at launch via userSetup.py, but I'm having trouble understanding how I would do this instead via a distributed plugin. The docs I've been looking at for custom commands, for example, are clear about what's necessary for Maya to recognize a registered command, but I don't see how to 'register' a custom menu. I tried to cheat my way around it by placing my buildMenu() code inside my custom command's initializePlugin() function, but that failed. I've seen one or two partial examples of a registerUI() method I can call, but I can't find any solid documentation on this. Anyway... just looking for some tips there on moving my custom menu out of the userSetup and into a shared plugin on the network.

How I've done it in the past is I put the menu creation in the plugin's initializePlugin, and the menu deletion in the plugin's uninitializePlugin.  In C++ it looks something like:

MString cmd = "ChaDeformationsMenu(\"mainDeformationsMenu\");";
       cmd+= "menuItem -p \"mainDeformationsMenu\" -divider true \"tbIMMenuDivider\";";
cmd+= "menuItem -p \"mainDeformationsMenu\" -l \"tbImageMultiplier\" -c (\"deformer -type tbImageMultiplier\") \"tbImageMultiplierMenuItem\";";
// cmd+= "menuItem -p \"mainDeformationsMenu\" -l \"tbSurfaceTension\" -c (\"deformer -type tbSurfaceTension\") \"tbSurfaceTensionMenuItem\";";
MGlobal::executeCommandOnIdle(cmd);

That is an odd one because I was actually adding onto Maya's deformation menu.  This will obviously be different depending on what you'd like to do.  Inside of the uninitializePlugin it looks like:

MGlobal::executeCommandOnIdle("deleteUI -mi \"tbIMMenuDivider\" \"tbImageMultiplierMenuItem\" \"tbSurfaceTensionMenuItem\";");

In Python you wouldn't need to call the C++ methods.


2. Is it possible to have a custom plugin auto-load without requiring the user to explicitly check the option to auto-load it in the Plugin Manager?

You would need to do this in a startup script or in a custom "plugin manager" which would also run via a startup script.  This is really the only way to accomplish something like this.  Once a user has loaded a plugin once, they can have it set to auto-load in the future...One other way (not sure how kosher this is) is to modify the user's auto-load preferences the first time they load your plugin...I've never actually done that before.

3. Maya 2015 seems to take much longer than 2014 to shutdown. Is it just me or is something really different here?

Haven't used 2015 yet so not sure about this one...

Hope this helps! 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPh%3D1bm6PAx37afDQOEx_s%2BLpdLMCApauAxnW1960REdmcBvJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
-tony

Justin Israel

unread,
Apr 21, 2014, 4:04:43 PM4/21/14
to python_in...@googlegroups.com


On Apr 22, 2014 3:49 AM, "Tim Crowson" <tcro...@gmail.com> wrote:
>
> I've got another set of questions here as I try to wrap my head around how Maya does things. I'm sure these are fairly mundane things in the end...
>
> 1. I know how to create my own custom menu at launch via userSetup.py, but I'm having trouble understanding how I would do this instead via a distributed plugin. The docs I've been looking at for custom commands, for example, are clear about what's necessary for Maya to recognize a registered command, but I don't see how to 'register' a custom menu. I tried to cheat my way around it by placing my buildMenu() code inside my custom command's initializePlugin() function, but that failed. I've seen one or two partial examples of a registerUI() method I can call, but I can't find any solid documentation on this. Anyway... just looking for some tips there on moving my custom menu out of the userSetup and into a shared plugin on the network.

Did it fail with an error or just not do anything? I would think it should work, being managed from the initialize function.  There is also the thing where you can specify a companion Mel script that will be called with your plugin.
Plugin aside, it can also be something in userSetup that just imports a shared module on the network.

>
> 2. Is it possible to have a custom plugin auto-load without requiring the user to explicitly check the option to auto-load it in the Plugin Manager?

That can be part of a shared python module being imported at startup or a Mel script in the scripts path that will get sourced automatically.

>
> 3. Maya 2015 seems to take much longer than 2014 to shutdown. Is it just me or is something really different here?
>
> Thanks again for any help!
>
> -Tim Crowson
> Magnetic Dreams
>

Tony Barbieri

unread,
Apr 21, 2014, 4:10:29 PM4/21/14
to python_in...@googlegroups.com
If the menu creation is failing in initializePlugin I recommend trying what I did in my example above by using MGlobal::executeCommandOnIdle if in C++ or executeDeferred/evalDeferred ( if in python as per our conversation the other day :) ).



For more options, visit https://groups.google.com/d/optout.



--
-tony

Tim Crowson

unread,
Apr 21, 2014, 5:02:00 PM4/21/14
to python_in...@googlegroups.com
Thanks guys! Turns out I'm a dork, who knew.. I had accidentally indented my initializePlugin() and uninitializePlugin() functions, so Maya was initializing a warm cup of jack squat, and of course gave no errors. Placing my call to build the menu inside initializePlugin() works just fine now.

-Tim


Reply all
Reply to author
Forward
0 new messages