PDA

View Full Version : Popup Menu of Shelves?


Windows90
09-17-2010, 08:27 AM
Hi guys!

I wonder how to add popup menu to speciafied shelf? Just like shelves of Peter Shipkov's awesome plugin SOuP.


and I also have another correlative question :D
When we drag from one DG node to another using MMB, there' a menu popuping in order for a easy connection.
My question is, How to edit this menu of my custom node?

Any help would be appreciated!

NaughtyNathan
09-17-2010, 07:52 PM
you can add a popupMenu to many controls very simply:
popupMenu -p "controlName"; // you need to specify the name of the parent control
menuItem -l "popup item #1" -c "doFunction";
menuItem -l "popup item #2" -c "doFunction";
menuItem -l "popup item #3, etc..." -c "doFunction";
setParent -m ..;
For shelf buttons it's exactly the same, but the tricky part is to find out the button name first:
shelfLayout -q -ca "shelfName"; // e.g. "Polygons"This will return all the control names for the buttons on the "polygons" shelf.
Once you've created the popup menu, you just need to save your shelf(s) and the popup menu should be stuck to that button forever. If you want to code a shelf button with a popup menu (in MEL/py), you just use the -menuItem (-mi) flag when creating the button:
shelfButton -p "Custom"
-iol "popup" -i "absolute.xpm"
-mi "popup item #1" "doFunction"
-mi "popup item #2" "doFunction"
; // etc...
:nathaN

NaughtyNathan
09-17-2010, 08:08 PM
as for your second Q about the mmb pop-up, that hypreGraph popup is controlled by the attributeMenu command. This has callback flags so you can create your own custom node menus.

:nathaN

Windows90
09-18-2010, 02:21 AM
Thanks Nathan!! You really do me a great favor!
I am try to make my custom node behavior like maya's build-in node in every aspect, now with your help I almost get there. :applause:

Thanks again!

ewerybody
09-23-2010, 10:54 AM
For some years now I use my script ezShelfStuff.mel (http://goodsoul.de/mel/ezShelfStuff.mel) (here is a zip with melDroplets along with the xpmBrowser (http://goodsoul.de/mel/ezShelfStuff.zip) (so you can drag & drop a script with the droplet from 7zip or WinRAR onto maya to install everything, standard explorer-zip-view needs extract)) :
http://img41.imageshack.us/img41/3923/ezshelfstuffsshot.png
I mean this just puts standard stuff to the rmbmenu but it maybe shows how you can do stuff..

Very good to know: for some time now Maya saves stuff that was attached as popupMenu to a shelf button!

Now this version of ezShelfStuff still updates everytime at lauch. But thats not much of an impact.

Another thing I was tinkering is small floating windows with shelfButtons that you make appear at the spot where you have the initial shelfButton. As an example:
http://img697.imageshack.us/img697/3594/floaterexample.png
global proc freezeBox()
{
if (`window -ex freezeBox`)
deleteUI freezeBox;
window -tb 0 freezeBox;
gridLayout;
popupMenu -button 3 -pmc "deleteUI freezeBox";
shelfButton -w 34 -h 34 -image "move_m.xpm"
-c "makeIdentity -apply 1 -t 1 -r 0 -s 0 -n 0; evalDeferred(\"deleteUI freezeBox\")";
shelfButton -w 34 -h 34 -image "rotate_m.xpm"
-c "makeIdentity -apply 1 -t 0 -r 1 -s 0 -n 0; evalDeferred(\"deleteUI freezeBox\")";
shelfButton -w 34 -h 34 -image "scale_m.xpm"
-c "ezFreezeScale; evalDeferred(\"deleteUI freezeBox\")";
showWindow freezeBox;
}

ndeboar
10-11-2010, 12:48 AM
hey,

This works fine for me, but when i restart maya, the menu disapears (eg, right click on the shelf, nothing happens).

Is there some way to get this to work after you restart maya?

Nick

Windows90
10-11-2010, 01:31 AM
Thanks Werner, I haven't check this thread util today, and thanks for your tips, I'll try that!

but when i restart maya, the menu disapears
The shelf's mel file would be rewritten every time "save shelves" command executed, and close maya is a situation. And the shelf menu rewritten by maya seems only support the "-mi" flag, if you create a menu use "popupMenu" following the shelf it would works well the first time but after rewriting it gone.. As well its name! :eek:

Now I use a "Init" shelf button to initialize the environment and setup the menu, for the shelf button lookup I create a function to loop through all the button's command attribute and find what's the correct one, rather primordial :sad: I think the Init function could be added to the "userSetup.mel" to run every time maya started. Hope there's a better way!

ndeboar
10-11-2010, 01:46 AM
support the "-mi" flag

Hmm, still doesnt work for me even with -mi, doesnt work after restart. Im using 2011, maybe they don't support it anymore?

claydough
10-11-2010, 03:18 AM
some links to popUp menu notes ( including shelfButton popUp and supporting userSetup.mel for restoration ):

http://tech-artists.org/forum/showthread.php?t=419



thanks for the feedback. nice to see some have a use for as much.

some more pop-up menu notes:
( maybe not as useful, but for completeness sake... )


shelfButton popUpMenus can be helpful for a generic script distribution ui.
( packing as much functionality in as less ui real estate as possible/reasonable )

Searching and restoring shelfButtons by annotation rather then labels
may be safer. As users are more likely to change labels.

pop up Menus can then be restored on subsequent Maya start-ups from userSetup.mel


A template for contextual shelfButtons:

dynamically create a menu of top level dag objects,
whose members optionally consists of submenus.
Hide/Show toggle cmd fer example functionality...


http://farm4.static.flickr.com/3310/3452659538_d76a6573f9_o.jpg
begin mel/*
cly_shelfButtonPopUpHide.mel

Roger Klado was here
because no one else will do it fer me
February 19, 2009 ( poppa )
RogerKlado@gmail.com ( Klado/Claydough/cly_ )

a template for shelfButton popUpMenus
*/

global proc cly_shelfButtonPopUpHide( string $parent )
{
if ( `control -exists $parent` ) { // then create a popupMenu for menuItems // control UI are received with a unique long pathname
string $uniqueMenu = "cly_hideMenu_"+ $parent;
// unique-ness is established by using UI's path. Assure UI name is legal by stripping "|"
while ( $uniqueMenu != ( $uniqueMenu = `substitute "|" $uniqueMenu "_"` ) ); // thanks to Byran Ewert! mel How-to #34

if ( `popupMenu -exists $uniqueMenu` )
deleteUI $uniqueMenu;

popupMenu
-parent $parent
-button 3
-postMenuCommand ( "cly_dynHideMenuItems \""+ $parent+ "\"" )
-allowOptionBoxes true
$uniqueMenu;
}
}

global proc cly_dynHideMenuItems( string $parent )
{
if ( `control -exists $parent` ) {
//
string $uniqueMenu = "cly_hideMenu_"+ $parent;
// unique-ness is established by using UI's path. Assure UI name is legal by stripping "|"
while ( $uniqueMenu != ( $uniqueMenu = `substitute "|" $uniqueMenu "_"` ) ); // thanks to Byran Ewert! mel How-to #34
//

popupMenu -e -deleteAllItems $uniqueMenu;

setParent -menu $uniqueMenu;
// dynamic popup menu items begin
//______________________________________________________________________

string $topTransforms[] = `ls -as`;

for ( $t in $topTransforms ) {
$tv = $t+ ".visibility";
string $cmd = "setAttr "+ $tv+ " ( ! `getAttr "+ $tv+ " ` );";

int $sm = 0;
string $dagTransforms[] = {};
$dagTransforms = `ls -dag -tr $t`;
if ( size( $dagTransforms ) > 1 )
$sm = 1;
menuItem
-label $t
-subMenu $sm
-command $cmd;

if ( size( $dagTransforms ) > 1 ) {
for ( $d in $dagTransforms ) {
$dv = $d+ ".visibility";
string $cmd = "setAttr "+ $dv+ " ( ! `getAttr "+ $dv+ " ` );";

menuItem
-label $d
-command $cmd ;
if ( $d == $dagTransforms[0] )
menuItem -divider true;
}
setParent -menu $uniqueMenu;
}
}
}
}
// end ( insert applause here ) end mel

the original userSeup.mel code to restore popUpMenus on subsequent Maya start ups failed to account for closed shelf gui states:

fail...

the userSetup.mel code to re-establish shelfButton popUp menus will fail if the tablayout is not visible.
( the `lsUI` control search will fail )

if the shelf is not visible toggle it open
int $visible = 1;
if ( ! `isUIComponentVisible "Shelf"` ) {
// dependent on internal maya scripts
$visible = 0;
toggleUIComponentVisibility "Shelf";
}

updated userSetup code template:
// supporting userSetup.mel annotaion search source code

// add the following lines to your userSetup.mel for cly_shelfButtonPopUpHide shelfButton pop-Up menu rebuild:
// if no userSetup.mel exists in your scriptDirectory... then simply rename this file to userSetup.mel and place it in your scripts directory
{
int $visible = 1;
if ( ! `isUIComponentVisible "Shelf"` ) {
// dependent on internal maya scripts
$visible = 0;
toggleUIComponentVisibility "Shelf";
}
string $controlUI[] = `lsUI -long -ctl`;
for ( $b in $controlUI ) {
// query fer annotation instead of label ( users change labels )
string $annoCheck = `control -q -annotation $b`;
if ( $annoCheck == "cly hide shelf button" ) {
string $popUpMenuChildren[] = `control -q -popupMenuArray $b`;
if ( size( $popUpMenuChildren ) )
deleteUI $popUpMenuChildren;
cly_shelfButtonPopUpHide $b;
}
}
if ( !$visible ) {
// dependent on internal maya scripts
toggleUIComponentVisibility "Shelf"; // reset visibility preference
}
}
//end


sorry..
I do not know if the user setup restoration templates for shelf button popups werks with Maya's 2011 GUI


the shelfButton popUp menu in the template gives an example of a dynamically created GUI
(a menu of top level dag objects,
whose members optionally consists of submenus.
Hide/Show toggle cmd fer example functionality... )

ewerybody
10-11-2010, 08:37 AM
This works fine for me, but when i restart maya, the menu disapears (eg, right click on the shelf, nothing happens).

Is there some way to get this to work after you restart maya?

NickThe ezShelfStuff.mel (http://goodsoul.de/mel/ezShelfStuff.mel) would have to be executed in the userSetup.mel as well. Namely its just: ezShelfStuff; What you would have to add to userSetup.mel in you scripts dir (internalVar -usd;).
The melDrop installer in the zip (http://goodsoul.de/mel/ezShelfStuff.zip) does all that automatically if you let it.

marcovn
10-12-2010, 10:10 PM
hey,

This works fine for me, but when i restart maya, the menu disapears (eg, right click on the shelf, nothing happens).

Is there some way to get this to work after you restart maya?

Nick

This is a known bug in Maya2011. I reported it in april and got this answer:

Thanks for submitting bug 356078: Shelves looses "menuItem"-Commands when exiting Maya
As a work-around until you get a fix, you might make that file un-writable, so Maya can't overwrite it upon exit.
Thanks, JohnCreson

We all love those Maya-workarounds, aren't we?

Windows90
10-19-2010, 10:48 AM
Long time no see guys! Thanks all of you for the great tips! CGtalk is really a good place!

CGTalk Moderation
10-19-2010, 10:48 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.