/* selectionEditorWin.mel Creation Date: 6-11-99 Author: robin (robin@uberware.net) http://www.uberware.net/mel/ Version: 1.6 Description: a way to save selections for later use Usage: selectionWindow; Notes: The selection editor is exactly like the layer editor. Actually, layers and saved selections are both just sets. The layer sets are part of a partition, and an object can only belong to one layer. But the same object can be in as many selection sets as you like. These sets are integrated with the Maya Quick Sets in the edit menu. A set created with this window will appear in that menu, and vice versa. As a matter of fact, I have customized the buildEditMenu.mel script to compliment this one, and you should be able to find it at http://browse.to/mel along with the latest version of this one. Version 1.6: 7-21-99 - Overrides the Edit menu commands inside this script. Add this line to your userSetup.mel: scriptJob -ro true -cf "busy" "source selectionEditorWin.mel"; - Tested with Maya 2.0 Limitations: - If you undo the sets commands, the list doesn't update correctly. Cllick the Update button if you undo past any operations you've done with this window. - Importing and Referencing actually work correctly (as far as my limited testing has shown), but for some reason, there's no "SceneOpened" event during these times, the list won't update correctly. Close and re-open the window. Disclaimer: Use and modify at your own risk! */ proc int isValidName( string $name ) // Description: // This procedure checks if the given string is a valid object // name. It returns true if it is, false otherwise. // { int $isValid = true; // check if name contains invalid characters string $regex = "[^0-9a-zA-Z_]"; string $match = match( $regex, $name ); if ($match != "") { $isValid = false; confirmDialog -title "Alert" -button "OK" -defaultButton "OK" -message " Name contains illegal characters. Please select another. " -parent selectionEditorWnd; } else { // check if name begins with an alphabetic character $regex = "[a-zA-Z_][0-9a-zA-Z_]*"; $match = match( $regex, $name ); if ($match != $name) { $isValid = false; confirmDialog -title "Alert" -button "OK" -defaultButton "OK" -message " Name is not valid. Please select another. " -parent selectionEditorWnd; } } return $isValid; } global proc renameSelection( string $currentSelectionName ) { // // Prompt the user for a new selection name // string $result = `promptDialog -title "Rename Selection" -message "Enter New Selection Name:" -text $currentSelectionName -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -dismissString "Cancel" -parent selectionEditorWnd`; // // If the result was "OK", then proceed // if ( $result == "OK" ) { // // Query the promptDialog for the name the // user typed in - note: there is no checking // being done for illegal characters, spaces, // etc. This should be added. // // The set is created in the selection partition // first, then the elements are forced into // the set, so that exclusivity can be maintained, // and the set creation won't fail before it's // even created. // string $newSelectionName = `promptDialog -q`; if ( isValidName($newSelectionName) ) { if (catch($newSelectionName = `rename $currentSelectionName $newSelectionName`)) { // // error due to non - unique name for context // confirmDialog -title "Alert" -button "OK" -defaultButton "OK" -message " Error in trying to rename Selection. Please select another " -parent selectionEditorWnd; } else { string $selectionEntryName = ( $newSelectionName + "SelectionItem" ); string $oldSelectionEntryName = ( $currentSelectionName + "SelectionItem" ); // change the label of the menu item and rename // the menu item menuItem -e -l $newSelectionName $oldSelectionEntryName; renameUI $oldSelectionEntryName $selectionEntryName; } } } } global proc string[] listAllSelections() { string $sets[] = `ls -sets`; string $selections[]; int $i = 0; for( $item in $sets ) { if( `sets -q -t $item` == "gCharacterSet" ) { $selections[$i] = $item; $i++; } } return $selections; } global proc updateSelectionEditorButtons( ) { // If something is selected in the selection // list, then enable the appropriate buttons, // otherwise disable the ones that require that // sets/selections are selected // if( 0 == `textScrollList -q -nsi selectionList` ) { button -e -enable false renameButton; button -e -enable false deleteButton; button -e -enable false hideButton; button -e -enable false showButton; button -e -enable false transferButton; } else if( 1 == `textScrollList -q -nsi selectionList` ) { button -e -enable true renameButton; button -e -enable true deleteButton; button -e -enable true hideButton; button -e -enable true showButton; button -e -enable true transferButton; } else { button -e -enable false renameButton; button -e -enable true deleteButton; button -e -enable true hideButton; button -e -enable true showButton; button -e -enable false transferButton; } } global proc updateSelectionEditorWnd( ) { // Fill the set list // textScrollList -e -ra selectionList; string $sets[] = `ls -sets`; for( $item in $sets ) if (`sets -q -t $item` == "gCharacterSet") textScrollList -e -a $item selectionList; } global proc selectionCmd( string $cmd ) { switch( $cmd ) { case "new": defineCharacter; updateSelectionEditorWnd; break; case "rename": // Rename the selected sets string $selSets[] = `textScrollList -q -si selectionList`; renameSelection $selSets[0]; updateSelectionEditorWnd; break; case "transfer": // Transfer selected to selected selection string $selSets[] = `textScrollList -q -si selectionList`; if( size( `ls -sl` ) == 0 ) { warning( "No objects selected to transfer to " + $selSets[0] ); return; } sets -e -fe $selSets[0]; break; case "delete": // Delete the selected sets // string $selSets[] = `textScrollList -q -si selectionList`; for( $set in $selSets ) { delete $set; } updateSelectionEditorWnd; break; case "hide": // Hide the selected sets // string $selSets[] = `textScrollList -q -si selectionList`; for( $set in $selSets ) { hide $set; } break; case "show": // Show the selected sets // string $selSets[] = `textScrollList -q -si selectionList`; for( $set in $selSets ) { showHidden $set; } break; case "hideall": // Hide all selection sets // string $selections[] = `listAllSelections`; for( $item in $selections ) { hide $item; } break; case "showall": // Hide all selection sets // string $selections[] = `listAllSelections`; for( $item in $selections ) { showHidden $item; } break; case "select": // Select selection sets // string $selSets[] = `textScrollList -q -si selectionList`; select -d; for( $set in $selSets ) { select -add $set; } break; case "template": // Template selection sets // string $selSets[] = `textScrollList -q -si selectionList`; select -d; for( $set in $selSets ) { toggle -template -state on $set; } break; case "untemplate": // Template selection sets // string $selSets[] = `textScrollList -q -si selectionList`; select -d; for( $set in $selSets ) { toggle -template -state off $set; } break; case "selectall": // Select all selection sets // string $selections[] = `listAllSelections`; select -d; for( $item in $selections ) { select -add $item; } break; } } global proc selectionEditorWin( ) { if( `window -exists selectionEditorWnd` ) { updateSelectionEditorWnd; showWindow selectionEditorWnd; return; } // GG: don't hardcode the HEIGHT! It doesn't work X-platform window -t "Selection Editor" -w 223 -iconName "Selections" -s true selectionEditorWnd; formLayout selectionEditorForm; textScrollList -ams true -dkc "selectionCmd delete" -dcc "selectionCmd select" -sc "updateSelectionEditorButtons" selectionList; separator -style "in" selectionSep; columnLayout selectionEdBtnLayout; button -h 26 -w 80 -l "New" -c "selectionCmd new" newButton; button -h 26 -w 80 -l "Rename" -c "selectionCmd rename" -enable false renameButton; button -h 26 -w 80 -l "Remove" -c "selectionCmd delete" -enable false deleteButton; button -h 26 -w 80 -l "Add" -c "selectionCmd transfer" -enable false transferButton; separator -style "in" -w 80 -h 10; button -h 26 -w 80 -l "Hide" -c "selectionCmd hide" -enable false hideButton; button -h 26 -w 80 -l "Hide All" -c "selectionCmd hideall" -enable true hideAllButton; separator -style "in" -w 80 -h 10; button -h 26 -w 80 -l "Show" -c "selectionCmd show" -enable false showButton; button -h 26 -w 80 -l "Show All" -c "selectionCmd showall" -enable true showAllButton; separator -style "in" -w 80 -h 10; button -h 26 -w 80 -l "Template" -c "selectionCmd template" -enable true templateButton; button -h 26 -w 80 -l "Untemplate" -c "selectionCmd untemplate" -enable true unTemplateButton; separator -style "in" -w 80 -h 10; button -h 26 -w 80 -l "Select" -c "selectionCmd select" -enable true selButton; button -h 26 -w 80 -l "Select All" -c "selectionCmd selectall" -enable true selAllButton; setParent ..; button -h 26 -w 80 -l "Update" -c "updateSelectionEditorWnd" updateButton; button -h 26 -w 80 -l "Close" -c "deleteUI selectionEditorWnd" closeButton; setParent ..; formLayout -e -af selectionList top 5 -ac selectionList right 5 selectionEdBtnLayout -af selectionList left 5 -ac selectionList bottom 5 selectionSep -af selectionEdBtnLayout top 5 -af selectionEdBtnLayout right 5 -an selectionEdBtnLayout left -ac selectionEdBtnLayout bottom 5 selectionSep -af selectionSep left 0 -af selectionSep right 0 -ac selectionSep bottom 5 updateButton -an selectionSep top -af updateButton left 5 -af updateButton bottom 5 -ap updateButton right 3 50 -an updateButton top -ap closeButton left 2 50 -af closeButton bottom 5 -af closeButton right 5 -an closeButton top selectionEditorForm; // Create script jobs to keep the selection editor up to date // when new selections are added to the system, File -> New // is performed, or a file is imported/opened scriptJob -p "selectionEditorWnd" -e "NewSceneOpened" "updateSelectionEditorWnd"; scriptJob -p "selectionEditorWnd" -e "SceneOpened" "updateSelectionEditorWnd"; updateSelectionEditorWnd; showWindow selectionEditorWnd; } // override default Maya procs for the edit menu global proc defineCharacter( ) // // Procedure Name: // defineCharacter // // Description: // Creates a set using the selected items, // so that users can define all the nodes // in the DAG that make up their "characters". // // Input Arguments: // None. // // Return Value: // None. { // Prompt the user for a new character name // string $result = `promptDialog -title "Create Quick Select Set" -message "Enter Quick Select Set name:" -text "Set" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -dismissString "Cancel"`; // If the result was "OK", then proceed // if ( $result == "OK" ) { // Also, notice that the `type` is being set // to "gCharacterSet" - just trying to pick // a name that users probably won't type // string $characterName = `promptDialog -q`; sets -text "gCharacterSet" -name $characterName; // if the selection editor window is open, update the list /**********************************/ if (`window -ex selectionEditorWnd`) updateSelectionEditorWnd; /**********************************/ } } global proc createCharacterMenu( string $parent ) // // Creates entries in the "Select Character" subMenu // in the Edit Menu. { setParent -m $parent; menu -e -dai $parent; menuItem -l "Selection Editor" -c "selectionEditorWin"; menuItem -divider true; // Get a list of all character sets in the // system, then generate an entry per set // string $charSets[] = `ls -sets`; for( $character in $charSets ) { if( `sets -q -t $character` == "gCharacterSet" ) { menuItem -l $character -c ( "select -r " + $character ); } } // changed the 0 to a 2 to account for our items if( `menu -q -ni $parent` == 2 ) // // No characters defined - create a default menu item // to inform the user { menuItem -l "No Quick Select Sets Defined" -enable false; } }