Tuesday, April 5, 2011

Maya Shelves as Marking Menus

I've been sitting on this one for some time to be honest, since March last year! Why have I been holding out on you? Because it's one of those things that you only really set up once and then you forget about it.

I was on CG Society a while back and I asked if anyone knew of a way to store all your shelves as some sort of marking menu. Well, CGSociety's NaughtyNathan obliged me, and here's what came out of it:

Use the instructions below to create custom hotkeys, or this script to do it automatically:

{
// define the command strings
string $pressCmd = "if( `popupMenu -exists tempMM` ) deleteUI tempMM;popupMenu -sh 1 -mm 1 -b 1 -aob 0 -p viewPanes -pmc buildShelvesMM tempMM";
string $releaseCmd = "MarkingMenuPopDown;";
// create the runTimeCommands. this isn't absolutely necessary, but it gives the hotkey
// a real command attachment so it can be seen and edited in the hotkey Editor:
runTimeCommand -ann "Press hotkey for shelf MM" -category "User Marking Menus" -c $pressCmd "hkShelfMMpress";
runTimeCommand -ann "Release hotkey for shelf MM" -category "User Marking Menus" -c $releaseCmd "hkShelfMMrelease";
// create the nameCommands (this is what the hotkey attaches to):
nameCommand -ann "hkShelfMMpress" -c "hkShelfMMpress" "hkShelfMMpressNameCommand";
nameCommand -ann "hkShelfMMrelease" -c "hkShelfMMrelease" "hkShelfMMreleaseNameCommand";
// define the actual hotkeys:
hotkey -keyShortcut "X" -n "hkShelfMMpressNameCommand"; // SHIFT-X
hotkey -keyShortcut "X" -rn "hkShelfMMreleaseNameCommand"; // SHIFT-X
}



Hotkey Instructions:


Open Maya, and from the menu go to Window, Settings/Preferences, Hotkey Editor.

Down the bottom to the right, click New (next to the Name box) to create a new command, and call it "hkShelfMMpress". Change the category to User from the rollout, and in the command box, paste the following:

//----------------------- if( `popupMenu -exists tempMM` ) deleteUI tempMM; popupMenu -sh 1 -mm 1 -b 1 -aob 0 -p viewPanes -pmc "buildShelvesMM" tempMM; //-----------------------


Click Accept.

You will notice the Assign New Hotkey box on the upper right is no longer disabled. In the Key box, type shift + x (it will appear as X in the key window, as the shift is expressed as a capital of the key). Click Assign.

Click the New button again to create a second hotkey. Name this one "hkShelfMMrelease", make sure the category is still 'User' and paste the following code into the Command box:

//----------------------- MarkingMenuPopDown; //-----------------------


Click accept, and make sure the right command (hkShelfMMrelease) is selected in the Commands window. With this selected, type shift + x again into the key box in the Assign New Hotkey box on the right. Change the direction to "Release" and click Assign.

Save and close.

Now when you hold shift + x and left click and hold in a viewport, a menu will pop up. This menu is a list of all the commands in your shelves. Note that at first, only one or two shelves will appear in this menu. Only the shelves you have opened in the session will be available. To activate additional shelves in this menu, you must click the corresponding shelf tab normally at the top of the Maya window and it will become available. Commands added to the shelf will be immediately available in the hotkey menu.

Note: Not all hotkeys will work with this script, the one given in these instructions will. Please remember to restart Maya or rehash after placing the file in the appropriate directory.

Once you've got that setup, save the following code in a file called buildShelvesMM.mel and put it in your \My Docs\maya\scripts\ or wherever your default scripts folder is:


// uses the internal tempMM to display all your shelves
// and their contents on a hotkeyed Marking Menu
// Original Script - Naughty Nathan - 24/03/10
// Disabled shelves not loaded from marking menu - Leon Woud 25/03/10
global proc buildShelvesMM()
{
menu -e -dai tempMM;
global string $gShelfTopLevel;
if (!`tabLayout -ex $gShelfTopLevel`)
{
menuItem -en 0 -l "Global ShelfLayout does not exist!";
return;
}
string $shelves[] = `shelfTabLayout -q -ca $gShelfTopLevel`;
for ($shelf in $shelves)
{
string $buttons[] = `shelfLayout -q -ca $shelf`;
if (`size($buttons)`)
{
menuItem -sm 1 -l $shelf;
for ($button in $buttons)
{
string $label = `shelfButton -q -l $button`;
string $cmd = `shelfButton -q -c $button`;
menuItem -l $label -c $cmd;
}
setParent -m ..;
}
}
setParent -m ..;
}


And voila! Shelf marking menus.

Note: This script ONLY loads the shelves you've already accessed in your current session into the marking menus, this is just to keep stuff neat and tidy. If you'd like a version which loads all your shelves, check out the original thread here:
http://forums.cgsociety.org/showthread.php?f=7&t=865857


Original script by Naughty Nathan, CG Society - 24 March 2010
Shelves not loaded will not be displayed functionality by Leon Woud - 25 March 2010
Documentation by Oana Croitoru - 25 March 2010

No comments:

Post a Comment