All code here is provided as is without support.
Use at your own risk! These posts assume you have some knowledge of import/running python script in maya.
If Gifs/Images are not displaying in Chrome try a different browser.
Used to mange nodeEditor right click menus
Please see the commented code at the bottom for usage
So the nodeEditor in Maya can register commands on Nodes using
The problem I found with this is it’s a bit hellish to manage (especially
So this is a little post for about me mashing together an approach to
facilitate managing adding commands to the nodeEditor via a little
menuManager of sorts. Why? Well reloading these menus over and over
does not remove the previous load!
So you have to remove them before the reload. Having a little manager to keep
track of what is loaded etc can be pretty helpful with this.
The idea here is to be able to add as many commands as I like to my
code base without having to maintain the manager `seeing’ this code.
To do this I’m going to add a little factory module in to scan for a
specific class in a path, and from that create a cache of all the commands
I want to create menus for.
Then the manager itself leverages that cache to add the menus to the
NodeEditor in Maya.
The Factory -Menu Cache
What this is doing is setting the base path to /menus relative to the
current filepath the factory.py lives in. Scan subfolders for the .py
files and looks to import the class(es) in each file.
Now this works because I have dictated a specfic structure for each command
Classes in any of these menu modules ARE MENUS! I don’t or won’t have
any classes that are NOT inheriting nem_base.MenuBase!
Functions in these modules are used by the Menu Classes.
Menu base is the base menu class used by the neMenuManager to create
the menus as expected in Maya.
Creating a menu.py
So inheriting / overloading this class is then fairly straight forward
for me to use when adding a new menu item to the nodeEditor.
eg: gitHub example
If you check the latest version of the file you can see each menu gets a
unique typeID, Name, and a function to call.
Note; No args are handled atm.
And each class has a related mayaNode that they are linked to when you
invoke a menu call in maya by right clicking over a node in the nodeEditor
From there The manager only needs to leverage the MENUCACHE to generate
all the menus and provide a way to handle this information
eg: adding/removing menus from the nodeEditor as expected.