So how can we customize default right-click menu in Maya?
First of all we have to know almost the whole maya UI is written in MEL (Maya Embedded Language). That means you can modify it extensively. Second, there is a concept of overriding and that means you don't have to actually modify the original .mel scripts just have to have a modified copy of those. I have a post about Maya customizing overview where you can read more detail customizing Maya paths. The default location template (on windows based on the official maya document) to place override scipts is the following:
drive:\Documents and Settings\username\My Documents\maya\version
You can query the actual maya script paths with a simple mel command:
getenv MAYA_SCRIPT_PATH
It returns the maya script paths list (MSPL) which starts with the custom maya script path (CMSP) and there is somewhere the default maya script path (DMSP). The template for DMSP is:
/application folder/scripts/
Overriding basically means copy the .mel file what you want to modify under the CMSP. Maya will recogzie two .mel script with a same name, and it will read the customized one (because it is the first path in MSPL).
Just have to know which particular .mel script is the one you have to modify to utilize custom default right-click menu.
Because it described in a .mel script which is basically a text file, you can searh for the word or words to find the script file. I this case the right-click menu has a menu item "Complet Tool" and this is enough to find the file.
Personally I use Total Commander to handle the file system so I can search not for the file name but the text.
You are going to find the buildObjectMenuItemsNow.res.mel. But! Maya .mel files often have a .res.mel version. Those file basically collect the texts which are displayed on the maya UI. It is managed by the uiRes mel function.
For us right now the important thing is we have to copy buildObjectMenuItemsNow.mel file under the CMSP because this is the file we want to modify.
This .mel file has a part which is exactly like a marking menu .mel file. I don't want to talk to much about managing marking menus but ask if something not clear.
The main issue with buildObjectMenuItemsNow.mel to replace the current menu items and/or add more.
So the important part of the code originally look like this:
setParent -menu $parentName;
menuItem
-label (uiRes("m_buildObjectMenuItemsNow.kSelectAll"))
-radialPosition "S"
-command ("SelectAll");
menuItem
-label (uiRes("m_buildObjectMenuItemsNow.kCompleteTool"))
-radialPosition "N"
-command ("CompleteCurrentTool");
setParent ..;
And we can replace menuItems like this:
menuItem
-label "Outliner"
-radialPosition "N"
-command "OutlinerWindow";
menuItem
-label "Graph Editor"
-radialPosition "E"
-command "GraphEditor";
menuItem
-label "NodeEditor"
-radialPosition "S"
-command "NodeEditorWindow";
menuItem
-label "Set Editor"
-command "setMembershipEditor"
-radialPosition "W";
Personally I prefer to arrange menuItems clockwise. That is why -radialPosition starts with "N" (north) and after "E" (east) and so on.
Footnote:
Usually there is an easier way to find a .mel script based on the procedure name. Turn on Echo All Command in Script Editor below History menu or push the button on the toolbar.
Now if you try default right-click menu it will return in the script editor history panel something like this:
buildObjectMenuItemsNow "MayaWindow|formLayout1|viewPanes|modelPanel4|...|modelPanel4ObjectPop";
We can use whatIs xyz.mel statement to check a mel procedure source. If you type:
whatIs buildObjectMenuItemsNow;
And the result would be something like this:
// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2012/scripts/others/buildObjectMenuItemsNow.mel //
You will notice Echo All Command can produce tons of code lines in the history panel depending on what you are doing. So if you are confused you can use the method described earlier.
We can use buildObjectMenuItemsNow.res.mel file to manage -label names of course. For this case I would not recommend that.
To find out more about Marking Menus just search for it on the internet. There could be sub-menus if you use -subMenu flag. To close the sub-menu you have to use setParent -m ..;. It is clever to indent the code to visualize where the sub-menu start.
menuItem
-label "Editor Windows"
-subMenu 1
-radialPosition "N";
menuItem
-label "Outliner"
-radialPosition "N"
-command "OutlinerWindow";
menuItem
-label "Graph Editor"
-radialPosition "E"
-command "GraphEditor";
menuItem
-label "NodeEditor"
-radialPosition "S"
-command "NodeEditorWindow";
menuItem
-label "Set Editor"
-command "setMembershipEditor"
-radialPosition "W";
setParent -m ..;
No comments:
Post a Comment