//******************************************************************************** // selectionCount.mel, version 1.0: Maya MEL script // by: David Lewis w.david.lewis at gmail period com // Notes: // This script shows number of objects selected in the HUD. // Usage: // Place in your script directory. Source it from the userSetup.mel // script, the script editor or the command line. // // You can also call the first function (wdlShowSelectionCountInHUD). //******************************************************************************** // Tweakable items // Change this if you need to change the optionVar name global string $gOptionVarName = "displayHUDSelectionCount"; //******************************************************************************** // The main function to kick things off. Shows the selection count in the HUD // -- loads the option var to determine visibility // -- adds the menu item in the Display->Heads Up Display // -- creates the HUD display // -- calls the checkbox handler to do the dislay // //******************************************************************************** global proc int wdlShowSelectionCountInHUD() { global string $gOptionVarName; // Add menu items to control the custom items // global string $gHeadsUpDisplayMenu; // Add a divider to separate Maya items from custom items menuItem -parent $gHeadsUpDisplayMenu -divider true; // Check if the optionVar exists. If so, get the value, // otherwise, create the value. int $displayValue; if (`optionVar -exists $gOptionVarName`) { $displayValue = `optionVar -query $gOptionVarName`; } else { optionVar -intValue $gOptionVarName 1; $displayValue = true; } // Add one menu item per heads up display object created above // menuItem -parent $gHeadsUpDisplayMenu -checkBox $displayValue -label "Selection Count" -command "wdlSelectionCountCheckboxHandler()" -annotation "Selection count: Toggle the display of selection count" myselectionCountItem; // Setup the display and call the handler to get initial visibility wdlCreateHUDDisplay(); wdlSelectionCountCheckboxHandler(); return 0; } //******************************************************************************** // The guts of getting the selection count. //******************************************************************************** global proc int wdlSelectionCount() { string $sel[] = `ls -sl -fl`; return `size $sel`; } //******************************************************************************** // Creates the HUD display //******************************************************************************** global proc int wdlCreateHUDDisplay() { headsUpDisplay -section 3 -block 5 -label "Selection:" -command "wdlSelectionCount()" -event "SelectionChanged" -nodeChanges "attributeChange" HUDSelectionCount; return 0; } //******************************************************************************** // Handles the selection change of the checkbox // Queries the checkbox state and makes the HUD display visible or not. //******************************************************************************** global proc int wdlSelectionCountCheckboxHandler() { global string $gOptionVarName; int $selected = `menuItem -query -checkBox myselectionCountItem`; if ($selected) { optionVar -intValue $gOptionVarName 1; headsUpDisplay -e -vis 1 HUDSelectionCount; } else { optionVar -intValue $gOptionVarName 0 ; headsUpDisplay -e -vis 0 HUDSelectionCount; } return 0; } wdlShowSelectionCountInHUD();