This is deceptively tricky to do right, or with little of maya’s built-in shelf functions i’ve found. Currently, I have tools that do exactly what you’re trying to do but it’s not what you may call simple, neither am I a mel “guru” for that matter .
I have a blog post that illustrates some code I wrote a while ago to dynamically load a floating shelf UI upon startup of Maya. Read that if you want an example, although i’ve changed the code quite a bit for my purposes from what’s on the post.
I agree with what someone said earlier that you need to put the shelf into its own function though for ease of calling it later if the UI gets deleted or for reloading the shelf. Also, the tricky part is to have buttons to save and edit the shelf automatically. Thinking down the road, along with the highlighting feature you’re talking about, you’re going to want to group controls in additional shelves or shelf tabs preferably so you’re going to want to have a pretty modular set of code to start with.
Here’s an example bit of code for programming a button “on the fly” as a command wrapper of sorts for making a button for saving the shelf UI.
First, saving which takes a shelfLayout name and a shelf save path location, and creates a command that you can attach to your shelf button. It uses the maya function for saving the shelf called “saveShelf” because it’s more convenient than coding it myself.
//A save shelf command to automatically save a shelf from a custom floating window.
global proc string saveShelfCommand (string $name, string $location) {
string $command = ("//
// Result: Save Shelf //\r"
+“global proc saveThisShelf(){
"
+” string $ja_sh = shelfLayout -q -p " +$name+ "
;
"
+" string $shelf = tabLayout -q -selectTab $ja_sh
;
"
+" string $tempDir = "" +$location+ “";
"
+” string $name = ("shelf_" + $shelf);
"
+" $path = ($tempDir + $name + ".mel");
"
+“\r if (!filetest -f $path
) {
"
+” warning ($path + " does not exist, creating…");
"
+" int $fileid = fopen($path, "w");
"
+" fprint($fileid, "");
"
+" fclose($fileid);
"
+" }
"
+“\r saveShelf($shelf, ($tempDir + $name));
"
+” print ($shelf + " was saved");
"
+“}
"
+”
saveThisShelf()")
;
return $command;
}
As an example, attach it to your shelf button inside a makeShelf() function like this:
…
shelfButton
-enableCommandRepeat 1
-enable 1
-width 34
-height 34
-manage 1
-visible 1
-preventOverride 0
-align “center”
-label “Save This Shelf”
-labelOffset 0
-font “tinyBoldLabelFont”
-imageOverlayLabel “save”
-image “commandButton.xpm”
-image1 “commandButton.xpm”
-style “iconOnly”
-marginWidth 1
-marginHeight 1
-annotation (“Use this button to save this shelf to a desired location.
"
+” Currently that location is "" +$sh_loc+ ""
")
-command saveShelfCommand $sh_name $sh_loc
;
…
This is compatible with Maya2009 so there is no background image functionality but hopefully the principles are being illustrated. Hope this helps! Believe me, you can get pretty creative when creating shelves like this.