///////////////////////////////////////////////////////////////////////////////
//
// Name: proc addColorToolsMenuItems(string $mayaMenuName)
//
// Input: string $mayaMenuName name of global menu to add to
//
// Output: none
//
// Desc: add our custom menu item to maya's editPolygon | Colors submenu
//
///////////////////////////////////////////////////////////////////////////////
proc addColorToolsMenuItems(string $mayaMenuName)
{
//need to know how many items are in the maya menu. If no items are there, we need to
// run the create script so maya will fill up the menu. If you add custom menu
// items to an empty maya menu, the menu will only have the custom items in it
// and will lose all the maya generated menu items.
int $numExistingItems = menu -query
-numberOfItems
$mayaMenuName
;
if ($numExistingItems == 0)
{
//no items, so use the maya command to build and fill up the menu. Maya sets this
// postMenuCommand in one of its init scripts.
string $mayaPostMenuCommand;
$mayaPostMenuCommand = `menu -query
-postMenuCommand
$mayaMenuName`;
eval($mayaPostMenuCommand);
}//end if, no items exist
//examine Maya's colors submenu.
// We are going to add our custom items to this sub menu.
// We need to look thru color submenu to see if we are already there
string $colorsSubMenu = "polyColorsItem";
int $numColorItems = `menu -query
-numberOfItems
$colorsSubMenu`;
//items in the color submenu
string $editPolyColorSubMenuItems[] = `menu -query
-itemArray
$colorsSubMenu`;
int $customMenuItemExists = 0;
for ($j = 0; $j < $numColorItems; $j++)
{
//see if we are already in this submenu
if ($editPolyColorSubMenuItems[$j] == "tgColorToolsMenuItem")
{
//item is there, so set the flag
$customMenuItemExists = 1;
break;
}
}//end for, numcoloritems
if ($customMenuItemExists == 0)
{
//our menu items aren't in the maya menu, so add them
//add a divider to make our menu item stand out
menuItem
-parent $colorsSubMenu
-divider true
"tgColorToolsMenuDivider";
//add the menu item
menuItem
-command "tgColorToolsUI"
-label "tgColor Tools Menu"
-parent $colorsSubMenu
"tgColorToolsMenuItem";
//add an option box to our menu item
menuItem
-command "tgColorToolsUI"
-optionBox true
-parent $colorsSubMenu
"tgColorToolsMenuItem\_OptionBox";
}//end if, not in menu
//if our menu items are already in the menu, there is nothing else we need to do.
}//end addcolortoolsmenuitems()
//------------------------------------------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
//
// Name: global proc int makeColorToolsMenus()
//
// Input: none
//
// Output: int $addedMenu 1 if we added our menu items, 0 otherwise
//
// Desc: add our custom menu item to maya's editPolygon | Colors submenu
//
///////////////////////////////////////////////////////////////////////////////
global proc int makeColorToolsMenus()
{
int $addedMenu = 0;
global string $gMainWindow; //maya's main window
if ($gMainWindow != "") //make sure we can see the window otherwise menu stuff won't add.
{
//get the "modeling" menu group because that is where we want to add items
global string $gModelingMenus[];
global string $gMainEditPolygonsMenu; //will be adding to the edit polygons menu
int $numMenus = `size $gModelingMenus`; //get number of menus in menu bar
int $menuIndex = -1;
//Need the menu index for the editPolygon menu in the Modeling menus
for ($i = 0 ; $i < $numMenus; $i++)
{
if (`match $gMainEditPolygonsMenu $gModelingMenus[$i]` != "")
{
//found our string in the current menu item string
$menuIndex = $i;
break;
}
}//end for, num menus
if ($menuIndex == -1) //couldn't find our menu, error
{
warning("unable to find maya menu to add our menu items ton");
}//end if, no menu
else
{
//although we now have the menuIndex for the menu we want to add to, we
// aren't currently using it. The code above is still useful to make sure
// the menu we want to add to will actually exist.
//go add our stuff to the found menu
addColorToolsMenuItems($gMainEditPolygonsMenu);
$addedMenu = 1;
}
}//end if, have main maya window
return $addedMenu;
}//end makecolortoolsmenus()
//------------------------------------------------------------------------------------------------------------------------
The code would look a lot better if the forum supported tabs.
g-