crouchingPIXEL – 3D Modeling – 3D Rigging – Animation

Adding Menu Items in Maya

April 27, 2011Tutorials

In this short article I would like to walk through the steps of adding menu items to existing Maya menus. Note that Maya Dev team is a bit chaotic which means that this will not necessary work on all menus (for some reason the structure of the skinning and skeleton procedures are different from the way the edit and assets menu are built).

The idea is quite simple. The ability to customize the UI extensively has always been a key selling point for Maya. Now we can harness this to our advantage by adding many tools to Maya’s built in menus.

Why bother?

That’s a good question and the answer is divided to two. One reason here is for exercise purposes and getting more familiar with Maya and her inner workings. The second reason is to add functionality across the “studio”, which means less shelves and small mel scripts that no one remembers where they are located or named, and on to the UI itself where it will become much more versed among the users.

The actual code

The first proc is responsible for adding the menu items we want to add to the specific Maya menu.

global proc string AddRandomMenuItems()
{
        // create a global variable for ui existance testing
        global int $gRandomItemAddTest;

        // test if the new menu item already exists
        if ($gRandomItemAddTest == 0)
        {
                menuItem -divider true;

                menuItem -label "Random Menu Item"
                        -annotation ("Something pretty random")
                        -c "RandomCmd" m_random1;

                $gRandomItemAddTest = 1;
        }
        return "RemoveRandomMenuItems()";
}
global proc RemoveRandomMenuItems()
{
       global int $gRandomItemAddTest;

        // test if exists
        if ($gRandomItemAddTest == 1)
        {
                // delete items
                deleteUI -mi m_random1;
        }
}

Now we are getting there! The init function is the one that will be called and is responsible for the actual attachment and execution of the add function

global proc RandomInit()
{
	global int $gRandomItemAddTest;
	global string $gPolygonsEditUVsMenu;
	$gRandomItemAddTest = 0;
	addMenuItemSafe($gPolygonsEditUVsMenu, "AddRandomMenuItems", "Random");
}

Example menu variables

$gMainAssetsMenu is used for the Assets menu.

$gMainDisplayMenu is used for the Display menu.

$gMainEditMenu is used for the Edit menu.

$gMainFileMenu is used for the File menu.

Finding more menu variables

Easy way to find is go to “C:\Program Files\Autodesk\Maya2011\scripts\startup\” and search for “*Menu.mel” which will return lots of Maya’s menu procedures and scripts. Just dive in and find the one you need.

Further reading

A nice article of UI customization technolumiere

© 2011 crouching pixelTop ↑