////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@gmail.com) // // Creation date : 30/I/2003 // v1.1 : 8/II/2003 // v1.2 : 13/II/2003 // v1.3 : 15/II/2003 // v1.5 : 6/III/2004 // v1.51 : 29/III/2004 // v1.75 : 27/VII/2005 // v1.76 : 12/VIII/2005 // v1.8 : 21/X/2005 // v1.85 : 24/X/2005 // v2.0 : 10/XII/2005 // v2.1 : 23/XII/2005 // v2.2 : 11/VIII/2006 // v2.21 : 29/VIII/2006 // v2.3 : 10/X/2006 // v2.5 : 17/X/2006 // v2.55 : 19/X/2006 // v2.56 : 9/XI/2006 // v2.56b : 9/XII/2006 // v2.56c : 12/XII/2006 // v2.7 : 18/XII/2006 // v2.71 : 19/XII/2006 // v2.71b : 5/X/2007 // v2.72 : 6/X/2007 // // Main procedure : type "llMakeButton" in the Command Line or Script Editor // ////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // // // DESCRIPTION // // This script will create a simple window with a button on it. Upon clicking on this button, // the user will be able to select again the objects that were selected when he called the script. // The button can be relabelled, and many different buttons can be created, thus allowing the user // to recall as many selections as he needs. To enhance the speed in the user's workflow, // the buttons can be re-colored, and also each window can individually be saved in the scene. // // *** NOTE : Right-mouse-clicking and middle-mouse-clicking on the buttons will make available // a lot of useful extra features !!! *** // // // VERSIONS HISTORY // // VERSION 1.1 // Now the window's "name" is actually its "title". If the user attemps to create a window that // already has this title, the existing window will be deleted. // // VERSION 1.2 // Now the script will check that the user has not left in blank the two text fields. If he did, the // script will NOT go on and will output an error instead. // // VERSION 1.3 // New visual for the button windows, taking up less screen space. // // VERSION 1.5 // Created dialog to allow the user to create a new window or replace it, if a window with the // same title is found to exist. // // VERSION 1.51 // Fixed a little bug that appeared in v1.5 // // VERSION 1.75 // Reworked some bits of the script. Now, if wanted, you can create the buttons directly through // MEL. Simply select something, then type : // llMakeButtonReg ("NAME") -- for the regular selection window // llMakeButtonPlus ("NAME") -- for the advanced selection window // // VERSION 1.76 // Now the confirmDialog optiion that pops up when the specified name already exists has // the options "Replace Window" or "Cancel". Upon the last, the llMakeButtonWindow is not // deleted either. // // VERSION 1.76b // The "+" and "-" buttons are now of fixed size. // // VERSION 1.8 // Implemented optional selection popup menus for each button. // // VERSION 1.85 // Implemented "toggle window titlebar" option on MMB-click on the buttons. // // VERSION 2.0 // Re-worked some of the code for more optimal use, and also added "save window configuration" feature. // It can be found on mmb-clicking, and it will create a scriptNode that exectues on opening/closing // the scene, which creates and deletes a button window exactly the way it was when created. // I also got rid of the "regular" button window. Now all the windows this script creates have // advanced selection buttons and popupMenus on right-click. // // VERSION 2.1 // After using the buttons to change the selection, the script changes the focus on the last found // model panel, instead of remaining inside the buttons like it used to. Not much of a change, // but should help work faster !! :-) // // VERSION 2.2 // Changed the coloration of the buttons & layout of the button window. Now the status of a saved/unsaved // button window is reflected in the background color of the formLayout, and the user can access a new feature // to customize the color of all the windows created by the script. This chosen color is saved in the scene, // with the window configuration. // // VERSION 2.21 // Fixed a little bug where the script didn't recall the button's color when the user tried to change it // after opening the scene the where button was saved in. // // VERSION 2.3 // Got rid of having to source the script beforehand. It seemed to confuse some users .. // Added a proc that, on loading a saved button, checks that all the nodes it contained on creation do exist // in the scene. Otherwise, the button is still created (without the missing node in the selection list), // but the button's border's color will make it appear as "non-saved". // // VERSION 2.5 // Added two new features on middle-clicking, "Change button label" and "Toggle +/- buttons". // I had to rework a good chunk of the script, to make old procs work correctly with the new ones, // and vice versa .. I think it was worth it though :-) // // VERSION 2.55 // Added a new feature on middle-mouse-clicking, "replace contents with current selection", which will // update the button's contents to the current Maya's selection list. // // VERSION 2.56 // Added two new features on middle-mouse-clicking, "adjust window size" and "adjust window position". // // VERSION 2.56b // Fixed a little bug where the newly saved windows appeared with the red frame when the scene was reopened. // // VERSION 2.56c // Now the window's size and position updates automatically when the user changes the numeric fields, // instead of having to click on "confirm" to see them. On clicking on "cancel", the window will go back // to the values it had before. // // VERSION 2.7 // Now the saved windows can be unloaded (automatically closed), and loaded up again by selecting "load window" // from the middle-mouse popup menu on any other visible button window. // // VERSION 2.71 // Added a middle-mouse option that prints out the contents of each button in the Script Editor. // Also, re-worked some chunks of code for optimization. // // VERSION 2.71b // Corrected a little bug that prevented the input windows to be correclty displayed in some OSs. // // VERSION 2.72 // Added small "+" / "-" buttons on the resize and re-position window. // // // Enjoy!! // // //////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// // GLOBAL VARIABLES // ////////////////////////////////// global string $LLMB_VERSION = "2.72" ; global string $WINDOW_INFO[] ; ////////////////////////////////// // llMBPrintContents // ////////////////////////////////// // // Prints out the contents of the button in the Script Editor. // // // <-- llMBEditWindowMenuitems // ////////////////////////////////// global proc llMBPrintContents (string $WINDOWNAME) { global string $WINDOW_INFO[] ; print ("// Contents of " + $WINDOW_INFO[0] + " : " + $WINDOW_INFO[12] + " //\n") ; } ; // global proc llMBPrintContents ////////////////////////////////// // llMBGetUnloadedWindows // ////////////////////////////////// // // Returns the list of found "unloaded" saved button windows. // // // <-- llMBUnloadedWindowExists // <-- llMBWindowLoader // ////////////////////////////////// global proc string[] llMBGetUnloadedWindows () { string $RETURN[] ; string $SCRIPTS[] = `llMBGetMBNamesFromScene "scripts"` ; for ($SCRIPT in $SCRIPTS) { string $WINDOWNAME = `llMBGetNameFromScript $SCRIPT` ; if (!`window -ex $WINDOWNAME`) $RETURN[(`size $RETURN`)] = $WINDOWNAME ; } ; // for return $RETURN ; } ; // global proc llMBGetUnloadedWindows ////////////////////////////////// // llMBUnloadedWindowExists // ////////////////////////////////// // // Returns 1 or 0, if any "unloaded" saved button windows are found. // // // <-- llMBWindowLoader // --> llMBGetUnloadedWindows // ////////////////////////////////// global proc int llMBUnloadedWindowExists () { string $WINDOWS[] = `llMBGetUnloadedWindows` ; if (`size $WINDOWS` > 0) return 1 ; else return 0 ; } ; // global proc llMBUnloadedWindowExists ////////////////////////////////// // llMBGetNameFromScript // ////////////////////////////////// // // Returns the name of the window, as stored in the // 22nd tokenized element of the beforeScript of the given scrtipNode. // // // <-- llMBWindowLoader // ////////////////////////////////// global proc string llMBGetNameFromScript (string $SCRIPT) { $AFTER_SCRIPT = (`scriptNode -q -as $SCRIPT`) ; string $BUFFER[] ; tokenizeList $AFTER_SCRIPT $BUFFER ; int $I = 0 ; return $BUFFER[22] ; } ; // global proc llMBGetNameFromScript ////////////////////////////////// // llMBGetLabelFromScript // ////////////////////////////////// // // Returns the label of the window, as stored in the // beforeScript scriptNode. // // // <-- llMBWindowLoader // ////////////////////////////////// global proc string llMBGetLabelFromScript (string $SCRIPT) { $BEFORE_SCRIPT = (`scriptNode -q -bs $SCRIPT`) ; string $BUFFER[] ; tokenizeList $BEFORE_SCRIPT $BUFFER ; $BEFORE_SCRIPT = `stringArrayToString $BUFFER " "` ; $BUFFER = `stringToStringArray $BEFORE_SCRIPT "\""` ; return $BUFFER[1] ; } ; // global proc llMBGetLabelFromScript ////////////////////////////////// // llMBWindowLoader // ////////////////////////////////// // // Creates a series of menuItems for the "load window" subMenu. // // // <-- llMBEditWindowMenuitems // --> llMBUnloadedWindowExists // --> llMBGetUnloadedWindows // --> llMBGetLabelFromScript // ////////////////////////////////// global proc llMBWindowLoader () { string $WINDOWLABEL ; if (`llMBUnloadedWindowExists`) for ($WINDOWNAME in `llMBGetUnloadedWindows`) { $WINDOWLABEL = `llMBGetLabelFromScript ($WINDOWNAME + "_SCRIPTNODE")` ; menuItem -l $WINDOWLABEL -c ("string $SEL[] = `ls -sl` ; eval (`scriptNode -q -bs " + $WINDOWNAME + "_SCRIPTNODE `) ; if (`size $SEL` > 0) select -r $SEL" ) ; } ; // for } ; // global proc llMBWindowLoader ////////////////////////////////// // llMBNewValueEntered // ////////////////////////////////// // // Updates the window's specified position of size values. // // // <-- llMBChangeNumericValues // --> llMBChangeStatusColor // ////////////////////////////////// global proc llMBNewValueEntered (int $DONE , string $VALUE , string $WINDOW) { int $VALUE1 = `intField -q -v llMBValue1` ; int $VALUE2 = `intField -q -v llMBValue2` ; int $CURRENTVALUE[] = eval ("window -q -" + $VALUE + " " + $WINDOW) ; int $MINVALUE[] ; if ($VALUE == "wh") { $MINVALUE[0] = 50 ; $MINVALUE[1] = 20 ; } else { $MINVALUE[0] = 0 ; $MINVALUE[1] = 0 ; } ; // if if (($VALUE1 < $MINVALUE[0]) || ($VALUE2 < $MINVALUE[1])) error ("Values must be higher than " + $MINVALUE[0] + " , " + $MINVALUE[1]) ; else { if (!(($VALUE1 == $CURRENTVALUE[0]) && ($VALUE2 == $CURRENTVALUE[1]))) { eval ("window -e -" + $VALUE + " " + $VALUE1 + " " + $VALUE2 + " " + $WINDOW) ; llMBChangeStatusColor $WINDOW 0 ; } ; // if if ($DONE) deleteUI llMakeButtonWindowNumericValues ; } ; // else } ; // global proc llMBNewValueEntered ////////////////////////////////// // llMBValueButton // ////////////////////////////////// // // Gets the value in the specified field, then edits it // to add or substract from it. // // // <-- llMBChangeNumericValues // ////////////////////////////////// global proc llMBValueButton (string $OPERATION, string $VALUE, int $FIELD) { int $VALOR = eval ("intField -q -v llMBValue" + $FIELD) ; if ($VALUE == "tlc") if ($OPERATION == "+") $VALOR -= 1 ; else $VALOR += 1 ; else if ($OPERATION == "+") $VALOR += 1 ; else $VALOR -= 1 ; eval ("intField -e -v " + $VALOR + " llMBValue" + $FIELD) ; } ; // global proc llMBValue Button ////////////////////////////////// // llMBChangeNumericValues // ////////////////////////////////// // // Creates a dialogue box asking that the user inputs numeric // values for either the Top-Left Corner or the Width and Height // of the source button window ; then updates it accordingly // if the user clicks on "Confirm". // // // <-- llMBEditWindowMenu // --> llMBNewValueEntered // --> llMBValueButton // ////////////////////////////////// global proc llMBChangeNumericValues (string $VALUE , string $WINDOW ) { // // VARIABLES // global string $LLMB_VERSION ; global string $WINDOW_INFO[] ; int $WIDTH = 220 ; int $HEIGHT = 155 ; string $LABEL[] ; if ($VALUE == "tlc") $LABEL = {"window position" , "Top Edge" , "Left Edge" , "^" , "v" , "<" , ">"} ; else $LABEL = {"window size" , "Width" , "Height" , "+" , "-" , "+" , "-"} ; int $VALUES[] = eval ("window -q -" + $VALUE + " " + $WINDOW) ; if (`window -ex llMakeButtonWindowNumericValues` == 1) deleteUI llMakeButtonWindowNumericValues ; window -title ("llMakeButtonWindow v" + $LLMB_VERSION) -minimizeButton 0 -maximizeButton 0 llMakeButtonWindowNumericValues ; // // LAYOUTS // formLayout llMakeButtonWindowFormLayout ; formLayout llMakeButtonWindowLayoutElement1 ; text -al center -l ("Adjust " + $LABEL[0]) llMBTextElement ; setParent .. ; formLayout llMakeButtonWindowLayoutElement2 ; text -al left -l $LABEL[1] llMBTextValue1 ; text -al left -l $LABEL[2] llMBTextValue2 ; intField -w 50 -v $VALUES[0] -cc ("llMBNewValueEntered ( 0 , \"" + $VALUE + "\" , \"" + $WINDOW + "\")") llMBValue1 ; intField -w 50 -v $VALUES[1] -cc ("llMBNewValueEntered ( 0 , \"" + $VALUE + "\" , \"" + $WINDOW + "\")") llMBValue2 ; button -l $LABEL[3] -c ("llMBValueButton (\"+\", \"" + $VALUE + "\" , 1) ; llMBNewValueEntered ( 0 , \"" + $VALUE + "\" , \"" + $WINDOW + "\")") llMBPlusValue1 ; button -l $LABEL[4] -c ("llMBValueButton (\"-\", \"" + $VALUE + "\" , 1) ; llMBNewValueEntered ( 0 , \"" + $VALUE + "\" , \"" + $WINDOW + "\")") llMBMinusValue1 ; button -l $LABEL[5] -c ("llMBValueButton (\"+\", \"" + $VALUE + "\" , 2) ; llMBNewValueEntered ( 0 , \"" + $VALUE + "\" , \"" + $WINDOW + "\")") llMBPlusValue2 ; button -l $LABEL[6] -c ("llMBValueButton (\"-\", \"" + $VALUE + "\" , 2) ; llMBNewValueEntered ( 0 , \"" + $VALUE + "\" , \"" + $WINDOW + "\")") llMBMinusValue2 ; setParent .. ; formLayout llMakeButtonWindowLayoutElement3 ; button -l "CONFIRM" -c ("llMBNewValueEntered ( 1 , \"" + $VALUE + "\" , \"" + $WINDOW + "\")") llMBButtonApply ; button -l "CANCEL" -c ("window -e -" + $VALUE + " " + $VALUES[0] + " " + $VALUES[1] + " " + $WINDOW + " ; deleteUI llMakeButtonWindowNumericValues") llMBButtonCancel ; setParent .. ; // // EDIT LAYOUTS // formLayout -e -attachForm llMBTextElement "top" 0 -attachForm llMBTextElement "bottom" 0 -attachForm llMBTextElement "left" 0 -attachForm llMBTextElement "right" 0 llMakeButtonWindowLayoutElement1 ; formLayout -e -attachForm llMBTextValue1 "top" 3 -attachNone llMBTextValue1 "bottom" -attachForm llMBTextValue1 "left" 0 -attachPosition llMBTextValue1 "right" 2 38 -attachForm llMBValue1 "top" 0 -attachNone llMBValue1 "bottom" -attachPosition llMBValue1 "left" 2 38 -attachNone llMBValue1 "right" -attachForm llMBPlusValue1 "top" 0 -attachNone llMBPlusValue1 "bottom" -attachControl llMBPlusValue1 "left" 5 llMBValue1 -attachNone llMBPlusValue1 "right" -attachForm llMBMinusValue1 "top" 0 -attachNone llMBMinusValue1 "bottom" -attachControl llMBMinusValue1 "left" 3 llMBPlusValue1 -attachNone llMBMinusValue1 "right" -attachForm llMBTextValue2 "top" 29 -attachNone llMBTextValue2 "bottom" -attachForm llMBTextValue2 "left" 0 -attachPosition llMBTextValue2 "right" 2 38 -attachForm llMBValue2 "top" 29 -attachNone llMBValue2 "bottom" -attachPosition llMBValue2 "left" 2 38 -attachNone llMBValue2 "right" -attachForm llMBPlusValue2 "top" 29 -attachNone llMBPlusValue2 "bottom" -attachControl llMBPlusValue2 "left" 5 llMBValue2 -attachNone llMBPlusValue2 "right" -attachForm llMBMinusValue2 "top" 29 -attachNone llMBMinusValue2 "bottom" -attachControl llMBMinusValue2 "left" 3 llMBPlusValue2 -attachNone llMBMinusValue2 "right" llMakeButtonWindowLayoutElement2 ; formLayout -e -attachForm llMBButtonApply "top" 0 -attachForm llMBButtonApply "bottom" 0 -attachForm llMBButtonApply "left" 0 -attachPosition llMBButtonApply "right" 5 50 -attachForm llMBButtonCancel "top" 0 -attachForm llMBButtonCancel "bottom" 0 -attachPosition llMBButtonCancel "left" 5 50 -attachForm llMBButtonCancel "right" 0 llMakeButtonWindowLayoutElement3 ; formLayout -e -attachForm llMakeButtonWindowLayoutElement1 "top" 10 -attachNone llMakeButtonWindowLayoutElement1 "bottom" -attachForm llMakeButtonWindowLayoutElement1 "left" 0 -attachForm llMakeButtonWindowLayoutElement1 "right" 0 -attachControl llMakeButtonWindowLayoutElement2 "top" 10 llMakeButtonWindowLayoutElement1 -attachNone llMakeButtonWindowLayoutElement2 "bottom" -attachForm llMakeButtonWindowLayoutElement2 "left" 30 -attachForm llMakeButtonWindowLayoutElement2 "right" 30 -attachControl llMakeButtonWindowLayoutElement3 "top" 10 llMakeButtonWindowLayoutElement2 -attachNone llMakeButtonWindowLayoutElement3 "bottom" -attachForm llMakeButtonWindowLayoutElement3 "left" 30 -attachForm llMakeButtonWindowLayoutElement3 "right" 30 llMakeButtonWindowFormLayout ; // // SHOW WINDOW // window -e -wh $WIDTH $HEIGHT llMakeButtonWindowNumericValues ; showWindow llMakeButtonWindowNumericValues ; } ; // global proc llMBChangeNumericValues ////////////////////////////////// // llMBUseCurrentSelection // ////////////////////////////////// // // Creates a dialogue box asking for confirmation, // then updates the button if the user clicks on "Yes". // // // <-- llMBEditWindowMenu // --> llMBExecMakeButtonPlus // --> llMBEditWindowAspect // --> llMBChangeStatusColor // ////////////////////////////////// global proc llMBUseCurrentSelection (string $WINDOWNAME) { global string $LLMB_VERSION ; global string $WINDOW_INFO[] ; string $CURRENT_SELECTION[] = `ls -sl` ; string $CONFIRM = `confirmDialog -title ("llMakeButton v" + $LLMB_VERSION + " - Confirm overwrite") -message "This will replace the button's selection list with the currently selected nodes.\nThis cannot be undone. Are you sure?" -button "Yes" -button "No" -defaultButton "Yes" -cancelButton "No" -dismissString "No"` ; if ($CONFIRM == "Yes") if (`size $CURRENT_SELECTION` > 0) { deleteUI ($WINDOWNAME) ; $NEW_WINDOWNAME = `llMBExecMakeButtonPlus ($WINDOW_INFO[0])` ; llMBEditWindowAspect ($NEW_WINDOWNAME , $WINDOW_INFO) ; llMBChangeStatusColor $WINDOWNAME 0 ; } // if (`size $SELECTION` > 0) else error ("select some nodes from the scene") ; } ; // global proc llMBUseCurrentSelection ////////////////////////////////// // llMBTogglePlusMinusButtons // ////////////////////////////////// // // Toggles the +/- buttons and edits the layout accordingly. // // // <-- llMBTogglePlusMinusButtons // <-- llMBEditWindowAspect // <-- llMBEditWindowMenu // ////////////////////////////////// global proc llMBExecTogglePlusMinusButtons (string $WINDOWNAME , int $VIS) { eval ("button -e -vis " + ($VIS) + " \"" + $WINDOWNAME + "_ADD\"") ; eval ("button -e -vis " + ($VIS) + " \"" + $WINDOWNAME + "_DES\"") ; if ($VIS) formLayout -e -attachForm ($WINDOWNAME + "_ADD") "top" 2 -attachForm ($WINDOWNAME + "_ADD") "left" 2 -attachForm ($WINDOWNAME + "_ADD") "bottom" 2 -attachNone ($WINDOWNAME + "_ADD") "right" -attachForm ($WINDOWNAME + "_SEL") "top" 2 -attachControl ($WINDOWNAME + "_SEL") "left" 2 ($WINDOWNAME + "_ADD") -attachForm ($WINDOWNAME + "_SEL") "bottom" 2 -attachControl ($WINDOWNAME + "_SEL") "right" 2 ($WINDOWNAME + "_DES") -attachForm ($WINDOWNAME + "_DES") "top" 2 -attachNone ($WINDOWNAME + "_DES") "left" -attachForm ($WINDOWNAME + "_DES") "bottom" 2 -attachForm ($WINDOWNAME + "_DES") "right" 2 ($WINDOWNAME + "_FORM") ; else formLayout -e -attachForm ($WINDOWNAME + "_SEL") "top" 2 -attachForm ($WINDOWNAME + "_SEL") "left" 2 -attachForm ($WINDOWNAME + "_SEL") "bottom" 2 -attachForm ($WINDOWNAME + "_SEL") "right" 2 ($WINDOWNAME + "_FORM") ; } ; // global proc llMBExecTogglePlusMinusButtons ////////////////////////////////// // llMBTogglePlusMinusButtons // ////////////////////////////////// // // Toggles the +/- buttons and edits the layout accordingly. // // // <-- llMBEditWindowMenuitems // --> llMBExecTogglePlusMinusButtons // ////////////////////////////////// global proc llMBTogglePlusMinusButtons (string $WINDOWNAME) { llMBExecTogglePlusMinusButtons ($WINDOWNAME , (!(eval ("button -q -vis \"" + $WINDOWNAME + "_DES\"")))) ; } ; // global proc llMBTogglePlusMinusButtons ////////////////////////////////// // llMBGetMBNamesFromScene // ////////////////////////////////// // // Returns a list of all the button windows in the scene. // // // <-- llMBDoesWindowExist // ////////////////////////////////// global proc string[] llMBGetMBNamesFromScene (string $TYPE) { string $COMMAND ; if ($TYPE == "windows") $COMMAND = "lsUI -windows" ; else if ($TYPE == "scripts") $COMMAND = "ls -type script" ; string $BUTTONS[] = `eval $COMMAND` ; string $RETURN[] ; int $I = 0 ; for ($BUTTON in $BUTTONS) if (`substring $BUTTON 1 5` == "LLMBW") { $RETURN[$I] = $BUTTON ; $I++ ; } ; // if return $RETURN ; } ; // global proc llMBGetMBNamesFromScene ////////////////////////////////// // llMBEditWindowAspect // ////////////////////////////////// // // Modifies the specified window's appearence with the // info passed on in $WINDOW_INFO. // // // <-- triggered by the startup scriptNode of each saved window // <-- llMBTogglePlusMinusButtons // <-- llMBNewLabelEntered // <-- llMakeButtonPlus // <-- llMBUseCurrentSelection // --> llMBExecChangeButtonsColor // --> llMBExecTogglePlusMinusButtons // --> llMBChangeStatusColor // ////////////////////////////////// global proc llMBEditWindowAspect (string $WINDOWNAME , string $WINDOW_INFO[]) { eval ("window -e -tb " + $WINDOW_INFO[10] + " -s " + $WINDOW_INFO[10] + " " + $WINDOWNAME) ; eval ("window -e -wh " + $WINDOW_INFO[2] + " " + $WINDOW_INFO[3] + " " + $WINDOWNAME) ; eval ("window -e -tlc " + $WINDOW_INFO[4] + " " + $WINDOW_INFO[5] + " " + $WINDOWNAME) ; llMBExecChangeButtonsColor $WINDOWNAME $WINDOW_INFO[6] $WINDOW_INFO[7] $WINDOW_INFO[8] ; llMBExecTogglePlusMinusButtons $WINDOWNAME $WINDOW_INFO[11] ; if ($WINDOW_INFO[9]) llMBChangeStatusColor $WINDOWNAME 1 ; } ; // global proc llMBEditWindowAspect ////////////////////////////////// // llMBExecMakeButtonPlus // ////////////////////////////////// // // Creates the button window with default position and coloring. // // // <-- llMBTogglePlusMinusButtons // <-- llMBNewLabelEntered // <-- llMakeButtonPlus // <-- llMBUseCurrentSelection // --> llMBWSetFocusOnModelPanel // --> llMBCreateSelectMenuItems // --> llMBEditWindowMenu // --> llMBChangeButtonsColor // --> llMBChangeStatusColor // ////////////////////////////////// global proc string llMBExecMakeButtonPlus (string $TXTNAMEBUTTON) { $TXTNAMEWINDOW = `tolower $TXTNAMEBUTTON` ; string $WINDOWNAME = ("LLMBW_" + `substituteAllString $TXTNAMEBUTTON " " "_"`) ; string $SELECTCMD = "" ; for ($ELEMENT in `ls -sl`) $SELECTCMD = ($SELECTCMD + $ELEMENT + " ") ; int $VALUES[] ; int $GOODVALUE ; string $SELECTION[] = `ls -sl` ; if (`window -ex $WINDOWNAME`) deleteUI -window $WINDOWNAME ; window -title $TXTNAMEWINDOW -minimizeButton 0 -maximizeButton 0 -iconName $TXTNAMEWINDOW $WINDOWNAME ; formLayout -numberOfDivisions 103 ($WINDOWNAME + "_FORM") ; button -l $TXTNAMEBUTTON -c ("select -r " + $SELECTCMD + "; llMBWSetFocusOnModelPanel ;") ($WINDOWNAME + "_SEL") ; llMBCreateSelectMenuItems ( "r" , $SELECTION ) ; llMBEditWindowMenu ($WINDOWNAME , $TXTNAMEBUTTON) ; button -l " + " -w 17 -c ("select -add " + $SELECTCMD + "; llMBWSetFocusOnModelPanel ;") ($WINDOWNAME + "_ADD") ; llMBCreateSelectMenuItems ( "add" , $SELECTION ) ; llMBEditWindowMenu ($WINDOWNAME , $TXTNAMEBUTTON) ; button -l " - " -w 17 -c ("select -d " + $SELECTCMD + "; llMBWSetFocusOnModelPanel ;") ($WINDOWNAME + "_DES") ; llMBCreateSelectMenuItems ( "d" , $SELECTION ) ; llMBEditWindowMenu ($WINDOWNAME , $TXTNAMEBUTTON) ; textField -vis 0 -tx "0.831 0.815 0.784" ($WINDOWNAME + "_COLOR") ; formLayout -e -attachForm ($WINDOWNAME + "_ADD") "top" 2 -attachForm ($WINDOWNAME + "_ADD") "left" 2 -attachForm ($WINDOWNAME + "_ADD") "bottom" 2 -attachNone ($WINDOWNAME + "_ADD") "right" -attachForm ($WINDOWNAME + "_SEL") "top" 2 -attachControl ($WINDOWNAME + "_SEL") "left" 2 ($WINDOWNAME + "_ADD") -attachForm ($WINDOWNAME + "_SEL") "bottom" 2 -attachControl ($WINDOWNAME + "_SEL") "right" 2 ($WINDOWNAME + "_DES") -attachForm ($WINDOWNAME + "_DES") "top" 2 -attachNone ($WINDOWNAME + "_DES") "left" -attachForm ($WINDOWNAME + "_DES") "bottom" 2 -attachForm ($WINDOWNAME + "_DES") "right" 2 ($WINDOWNAME + "_FORM") ; window -e -wh 150 100 -tlc 341 426 $WINDOWNAME ; llMBChangeButtonsColor ($WINDOWNAME) ; llMBChangeStatusColor $WINDOWNAME 0 ; showWindow $WINDOWNAME ; return $WINDOWNAME ; } ; // global proc llMBExecMakeButtonPlus ////////////////////////////////// // llMBGetWindowInformation // ////////////////////////////////// // // Returns a string[] (detailed below) with all the relevant info. // about the specified info. // // // <-- llMBEditWindowMenuItems // <-- llMBDoesWindowExist // <-- llMakeButtonPlus // ////////////////////////////////// global proc string[] llMBGetWindowInformation (string $WINDOWNAME) { string $RETURN[] ; // [00] : label // [01] : number of contained nodes // [02] : width // [03] : height // [04] : tlc (tc) // [05] : tlc (lc) // [06] : color r // [07] : color g // [08] : color b // [09] : scriptNode exists // [10] : titlebar / sizeable // [11] : +/- buttons // [12] : list of contained nodes // 0 : button name $RETURN[0] = `button -q -l ($WINDOWNAME + "_SEL")` ; // 1 : number of contained nodes string $SELECTCMD = `button -q -c ($WINDOWNAME + "_SEL")` ; string $CONTENTS[] ; int $SIZE = `tokenize $SELECTCMD $CONTENTS` ; $RETURN[1] = $SIZE - 5 ; // 2 - 3 : window wh $RETURN[2] = `window -q -w $WINDOWNAME` ; $RETURN[3] = `window -q -h $WINDOWNAME` ; // 2 - 3 : window tlc int $TLC[] = `window -q -tlc $WINDOWNAME` ; $RETURN[4] = $TLC[0] ; $RETURN[5] = $TLC[1] ; // 6 - 7 - 8 : color rgb string $COLOR = `textField -q -tx ($WINDOWNAME + "_COLOR")` ; string $CURRENTCOLOR[] ; tokenize ($COLOR , $CURRENTCOLOR) ; $RETURN[6] = $CURRENTCOLOR[0] ; $RETURN[7] = $CURRENTCOLOR[1] ; $RETURN[8] = $CURRENTCOLOR[2] ; // 9 : scriptNode exists $RETURN[9] = 0 ; string $SCRIPTNODE = ($WINDOWNAME + "_SCRIPTNODE") ; string $SCRIPTS[] = `ls -type script` ; for ($SCRIPT in $SCRIPTS) if ($SCRIPT == $SCRIPTNODE) $RETURN[9] = 1 ; // 10 : titlebar / sizeable $RETURN[10] = `window -q -tb $WINDOWNAME` ; // 11 : +/- buttons $RETURN[11] = eval ("button -q -vis \"" + $WINDOWNAME + "_DES\"") ; // 12 : list of contained nodes $RETURN[12] = eval ("button -q -c " + $WINDOWNAME + "_SEL") ; $RETURN[12] = eval ("substring \"" + $RETURN[12] + "\" 11 " + (`size $RETURN[12]` -30)) ; // return RETURN return $RETURN ; } ; // global proc llMBGetWindowInformation ////////////////////////////////// // llMBDoesWindowExist // ////////////////////////////////// // // Returns 0 or 1 if a button window with the specified. // label is found in the scene // // // <-- llMakeButtonPlus // --> llMBGetMBNamesFromScene // --> llMBGetWindowInformation // ////////////////////////////////// global proc int llMBDoesWindowExist (string $LABEL) { string $WINDOWS[] = `llMBGetMBNamesFromScene "windows"` ; string $WINDOW ; string $WINDOW_INFO[] ; int $FOUND = 0 ; for ($WINDOW in $WINDOWS) { $WINDOW_INFO = `llMBGetWindowInformation $WINDOW` ; if ($WINDOW_INFO[0] == $LABEL) $FOUND = 1 ; } ; // for return $FOUND ; } ; // global proc llMBDoesWindowExist ////////////////////////////////// // llMBNewLabelEntered // ////////////////////////////////// // // Creates a window asking the user to enter the new label for the button. // // // --> llMBDoesWindowExist // --> llMBExecMakeButtonPlus // --> llMBEditWindowAspect // --> llMBSaveButtonWindow // ////////////////////////////////// global proc llMBNewLabelEntered (string $WINDOWNAME) { global string $WINDOW_INFO[] ; string $NEWLABEL = `textField -q -tx TXTBUTTONWINDOW` ; if (($NEWLABEL != $WINDOW_INFO[0]) && (`llMBDoesWindowExist $NEWLABEL`)) error ("A window with the specified label already exists") ; else if ($NEWLABEL == "") error ("specify a valid label") ; else { deleteUI llMakeButtonWindow ; if ($NEWLABEL != $WINDOW_INFO[0]) { string $CURRENT_SELECTION[] = `ls -sl` ; string $BUTTON_COMMAND = `button -q -c ($WINDOWNAME + "_SEL")` ; if ($WINDOW_INFO[9]) delete ($WINDOWNAME + "_SCRIPTNODE") ; else deleteUI ($WINDOWNAME) ; eval $BUTTON_COMMAND ; $NEW_WINDOWNAME = `llMBExecMakeButtonPlus ($NEWLABEL)` ; llMBEditWindowAspect ($NEW_WINDOWNAME , $WINDOW_INFO) ; if ($WINDOW_INFO[9]) llMBSaveButtonWindow ($NEW_WINDOWNAME) ; select -r $CURRENT_SELECTION ; } ; // if } ; // else } ; // global proc llMBNewLabelEntered ////////////////////////////////// // llMBChangeButtonLabel // ////////////////////////////////// // // Creates a window asking the user to enter the new label for the button. // // // <-- llMBEditWindowMenu // ////////////////////////////////// global proc llMBChangeButtonLabel (string $WINDOW) { // // VARIABLES // global string $LLMB_VERSION ; global string $WINDOW_INFO[] ; int $WIDTH = 325 ; int $HEIGHT = 95 ; if (`window -ex llMakeButtonWindow` == 1) deleteUI llMakeButtonWindow ; window -title ("llMakeButtonWindow v" + $LLMB_VERSION) llMakeButtonWindow ; // // LAYOUTS // formLayout llMakeButtonWindowFormLayout ; formLayout llMakeButtonWindowLayoutElement1 ; text -l "New Button Label : " llMBTextElement ; textField -tx $WINDOW_INFO[0] TXTBUTTONWINDOW ; setParent .. ; formLayout llMakeButtonWindowLayoutElement2 ; button -l "CONFIRM" -c ("llMBNewLabelEntered \"" + $WINDOW + "\"") llMBButtonApply ; button -l "CANCEL" -c ("deleteUI llMakeButtonWindow") llMBButtonCancel ; // // EDIT LAYOUTS // formLayout -e -attachForm llMBTextElement "top" 0 -attachNone llMBTextElement "bottom" -attachPosition llMBTextElement "left" 0 2 -attachPosition llMBTextElement "right" 0 35 -attachControl TXTBUTTONWINDOW "top" 0 llMBTextElement -attachForm TXTBUTTONWINDOW "bottom" 0 -attachPosition TXTBUTTONWINDOW "left" 0 35 -attachForm TXTBUTTONWINDOW "right" 0 llMakeButtonWindowLayoutElement1 ; formLayout -e -attachForm llMBButtonApply "top" 0 -attachForm llMBButtonApply "bottom" 0 -attachForm llMBButtonApply "left" 0 -attachPosition llMBButtonApply "right" 5 50 -attachForm llMBButtonCancel "top" 0 -attachForm llMBButtonCancel "bottom" 0 -attachPosition llMBButtonCancel "left" 5 50 -attachForm llMBButtonCancel "right" 0 llMakeButtonWindowLayoutElement2 ; formLayout -e -attachForm llMakeButtonWindowLayoutElement1 "top" 10 -attachForm llMakeButtonWindowLayoutElement1 "left" 5 -attachForm llMakeButtonWindowLayoutElement1 "right" 5 -attachNone llMakeButtonWindowLayoutElement1 "bottom" -attachControl llMakeButtonWindowLayoutElement2 "top" 10 llMakeButtonWindowLayoutElement1 -attachForm llMakeButtonWindowLayoutElement2 "left" 85 -attachForm llMakeButtonWindowLayoutElement2 "right" 85 -attachForm llMakeButtonWindowLayoutElement2 "bottom" 5 llMakeButtonWindowFormLayout ; // // SHOW WINDOW // window -e -minimizeButton 0 -maximizeButton 0 -wh $WIDTH $HEIGHT llMakeButtonWindow ; showWindow llMakeButtonWindow ; } ; // global proc llMBChangeButtonLabel ////////////////////////////////// // llMBCheckButtonContents // ////////////////////////////////// // // Checks that the nodes that the button is supposed to contain // do exist in the scene. Otherwise, a warning message is issued and // the missing node will be removed from the button's selection list. // // // <-- triggered by the startup scriptNode of each saved window // ////////////////////////////////// global proc int llMBCheckButtonContents (string $LABEL , string $SELECTCMD ) { int $ERROR = 0 ; string $CONTENTS[] ; int $SIZE = `tokenize $SELECTCMD $CONTENTS` ; select -cl ; for ($I = 0 ; $I <= $SIZE -1 ; $I++) { if (!(`objExists $CONTENTS[$I]`)) { $ERROR = 1 ; warning ("Node " + $CONTENTS[$I] + " was not found in the scene. Removing it from the selection list of button labeled \"" + $LABEL + "\"") ; $CONTENTS[$I] = "" ; } ; // if if ($CONTENTS[$I] != "") select -add $CONTENTS[$I] ; } ; // for string $SELECTION[] = `ls -sl` ; if (`size $SELECTION` == 0) $ERROR = 2 ; return $ERROR ; } ; // global proc llMBCheckButtonContents ////////////////////////////////// // llMBWSetFocusOnModelPanel // ////////////////////////////////// // // Sets the focus on the last found model panel. // // // <-- llMBExecMakeButtonPlus // <-- llMBCreateSelectMenuItems // ////////////////////////////////// global proc llMBWSetFocusOnModelPanel () { string $PANEL = `getPanel -wf` ; if (`modelPanel -ex $PANEL`) setFocus $PANEL ; } ; // global proc llSDWSetFocusOnModelPanel ////////////////////////////////// // llMBChooseButtonsColor // ////////////////////////////////// // // Creates a ColorEditor to choose the color of the window's buttons. // // // <-- llMBEditWindowMenu // --> llMBChangeButtonsColor // --> llMBChangeStatusColor // ////////////////////////////////// global proc llMBChooseButtonsColor (string $WINDOWNAME) { float $COLOR_x = 1.0 ; float $COLOR_y = 1.0 ; float $COLOR_z = 1.0 ; string $COLOR = `textField -q -tx ($WINDOWNAME + "_COLOR")` ; string $CURRENTCOLOR[] ; tokenize ($COLOR , $CURRENTCOLOR) ; vector $COLORTOHSV = eval ("rgb_to_hsv <<" + $CURRENTCOLOR[0] + " , " + $CURRENTCOLOR[1] + " , " + $CURRENTCOLOR[2] + ">>") ; $COLORTOHSV = << ($COLORTOHSV.x * 360) , $COLORTOHSV.y , $COLORTOHSV.z >> ; string $RESULT = eval ("colorEditor -hsv " + $COLORTOHSV) ; string $COLORBUFFER[] ; float $SUB_BUFFER[] ; tokenize ($RESULT, $COLORBUFFER) ; string $CHILDREN[] ; if ($COLORBUFFER[3] == 1) { $COLOR_x *= $COLORBUFFER[0] ; $COLOR_x /= 360.0 ; $COLOR_y *= $COLORBUFFER[1] ; $COLOR_z *= $COLORBUFFER[2] ; vector $NEWCOLOR = eval ("hsv_to_rgb << " + $COLOR_x + " , " + $COLOR_y + " , " + $COLOR_z + " >>") ; textField -e -tx ($NEWCOLOR.x + " " + $NEWCOLOR.y + " " + $NEWCOLOR.z) ($WINDOWNAME + "_COLOR") ; llMBChangeButtonsColor ($WINDOWNAME) ; llMBChangeStatusColor ($WINDOWNAME , 0) ; } ; // if } ; // global proc llMBChooseButtonsColor ////////////////////////////////// // llMBChangeButtonsColor // ////////////////////////////////// // // Gets the value of the window's "COLOR" textfield, // then calls on to the proc to actually change the color. // // // <-- llMBExecMakeButtonPlus // <-- llMBChooseButtonsColor // --> llMBExecChangeButtonsColor // ////////////////////////////////// global proc llMBChangeButtonsColor (string $WINDOWNAME) { string $COLOR = `textField -q -tx ($WINDOWNAME + "_COLOR")` ; string $CURRENTCOLOR[] ; tokenize ($COLOR , $CURRENTCOLOR) ; llMBExecChangeButtonsColor ($WINDOWNAME , $CURRENTCOLOR[0] , $CURRENTCOLOR[1] , $CURRENTCOLOR[2]) ; } ; // global proc llMBChangeButtonsColor ////////////////////////////////// // llMBExecChangeButtonsColor // ////////////////////////////////// // // Changes the color of the specified window's buttons' color to $COLORR , $COLORG , $COLORB. // // // <-- llMBEditWindowAspect // <-- llMBChangeButtonsColor // ////////////////////////////////// global proc llMBExecChangeButtonsColor (string $WINDOWNAME , string $COLORR , string $COLORG , string $COLORB) { int $PLUSMINUS_STATUS = eval ("button -q -vis \"" + $WINDOWNAME + "_DES\"") ; eval ("button -e -vis 0 " + ($WINDOWNAME + "_SEL")) ; if ($PLUSMINUS_STATUS) { eval ("button -e -vis 0 " + ($WINDOWNAME + "_ADD")) ; eval ("button -e -vis 0 " + ($WINDOWNAME + "_DES")) ; } ; // if ($PLUSMINUS_STATS) eval ("button -e -bgc " + $COLORR + " " + $COLORG + " " + $COLORB + " " + ($WINDOWNAME + "_SEL")) ; eval ("button -e -bgc " + $COLORR + " " + $COLORG + " " + $COLORB + " " + ($WINDOWNAME + "_ADD")) ; eval ("button -e -bgc " + $COLORR + " " + $COLORG + " " + $COLORB + " " + ($WINDOWNAME + "_DES")) ; eval ("button -e -vis 1 " + ($WINDOWNAME + "_SEL")) ; if ($PLUSMINUS_STATUS) { eval ("button -e -vis 1 " + ($WINDOWNAME + "_ADD")) ; eval ("button -e -vis 1 " + ($WINDOWNAME + "_DES")) ; } ; // if ($PLUSMINUS_STATS) textField -e -tx ($COLORR + " " + $COLORG + " " + $COLORB) ($WINDOWNAME + "_COLOR") ; } ; // global proc llMBExecChangeButtonsColor ////////////////////////////////// // llMBChangeStatusColor // ////////////////////////////////// // // Changes the color for the background color of the formLayout of the // button window, to either black or red, depending of the value of $SAVE. // // // <-- llMBNewValueEntered // <-- llMBTogglePlusMinusButtons // <-- llMBEditWindowAspect // <-- llMBExecMakeButtonPlus // <-- llMBChooseButtonsColor // <-- llMBSaveButtonWindow // <-- llMBEditWindowMenu // <-- llMakeButtonPlus // <-- llMBUseCurrentSelection // <-- triggered by the startup scriptNode of each saved window // ////////////////////////////////// global proc llMBChangeStatusColor (string $WINDOWNAME , int $SAVE) { vector $SAVED_COLOR = << 0.25 , 0.25 , 0.25 >> ; vector $UNSAVED_COLOR = << 1.0 , 0.4 , 0.4 >> ; vector $COLOR ; if ($SAVE) $COLOR = $SAVED_COLOR ; else $COLOR = $UNSAVED_COLOR ; formLayout -e -vis 0 ($WINDOWNAME + "_FORM") ; eval ("formLayout -e -bgc " + $COLOR + " " + ($WINDOWNAME + "_FORM")) ; formLayout -e -vis 1 ($WINDOWNAME + "_FORM") ; } ; // global proc llMBChangeStatusColor ////////////////////////////////// // llMBSaveButtonWindow // ////////////////////////////////// // // Saves the specified window by creating a startup scriptNode. // // // <-- llMBNewLabelEntered // <-- llMBEditWindowMenu // --> llMBChangeStatusColor // ////////////////////////////////// global proc llMBSaveButtonWindow (string $WINDOWNAME) { global string $LLMB_VERSION ; global string $WINDOW_INFO[] ; $WINDOW_INFO[9] = 1 ; // because the script will be saved - therefore it doesn't matter if it didn't !! // // COMMANDS TO BE SAVED // string $HEADER = "//\n// llMakeButton v" + $LLMB_VERSION + " configuration scriptNode\n// written by Lluis Llobera (lluisllobera@gmail.com)\n// MODIFY THIS AT YOUR OWN RISK\n//\r\n\r" ; string $CREATECMD = ("llMakeButtonPlus \"" + $WINDOW_INFO[0] + "\"") ; string $CHECKCMD = ("llMBCheckButtonContents (\"" + $WINDOW_INFO[0] + "\" , \"" + $WINDOW_INFO[(`size $WINDOW_INFO`-1)] + "\") ;") ; string $EDITCMD = ("llMBEditWindowAspect (\"" + $WINDOWNAME + "\" , {") ; for ($I = 0 ; $I <= (`size $WINDOW_INFO` -1) ; $I++) { if ($I == 0) $EDITCMD = ($EDITCMD + "\"" + $WINDOW_INFO[$I] + "\" , ") ; else if ($I == (`size $WINDOW_INFO` - 1)) $EDITCMD = ($EDITCMD + "\"" + $WINDOW_INFO[$I] + "\"}) ;") ; else $EDITCMD = ($EDITCMD + $WINDOW_INFO[$I] + " , ") ; } ; // for string $ERRORCMD = ("if ($LLMB_ERROR == 1) llMBChangeStatusColor \"" + $WINDOWNAME + "\" 0 ;") ; // // CREATE SCRIPTNODE // int $FOUND = 0 ; string $SCRIPTNODE = ($WINDOWNAME + "_SCRIPTNODE") ; string $SCRIPTS[] = `ls -type script` ; for ($SCRIPT in $SCRIPTS) if ($SCRIPT == $SCRIPTNODE) $FOUND = 1 ; if (!$FOUND) scriptNode -n $SCRIPTNODE ; setAttr ($SCRIPTNODE + ".scriptType") 1 ; scriptNode -e -bs ($HEADER + "\nsource llMakeButton ;\r\nint $LLMB_ERROR = " + $CHECKCMD + "\r\nif ($LLMB_ERROR != 2)\r\n {\r\n " + $CREATECMD + " ;\n " + $EDITCMD + "\r\n " + $ERRORCMD + "\r\n } ; // if\r\nselect -cl ;") $SCRIPTNODE ; scriptNode -e -as ($HEADER + "\ndeleteUI -window " + $WINDOWNAME + " ;") $SCRIPTNODE ; llMBChangeStatusColor ($WINDOWNAME , 1) ; } ; // global proc llMBSaveButtonWindow ////////////////////////////////// // llMBUpdateMenuItems // ////////////////////////////////// // // Updates the checkbox state of all the menu items in the specified popupMenu. // // // <-- llMBCreateSelectMenuItems // ////////////////////////////////// global proc llMBUpdateMenuItems (string $MENUNAME) { int $STARTINGNUMBER = 2 ; string $ITEMS[] = eval ("popupMenu -q -ia " + $MENUNAME) ; int $SIZE = `size $ITEMS` ; for ($I = $STARTINGNUMBER ; $I <= $SIZE - 1 ; $I++) { string $ITEM = $ITEMS[$I] ; string $OBJECT = eval ("menuItem -q -l " + $ITEM) ; menuItem -e -cb (llMBIsSelected ($OBJECT)) $ITEM ; } ; // for } ; // global proc llMBUpdateMenuItems ////////////////////////////////// // llMBIsSelected // ////////////////////////////////// // // Checks whether the specified object name is selected // // // <-- llMBCreateSelectMenuItems // <-- triggered by each of the menu items in the button's (+ / rel / -) selection list. // ////////////////////////////////// global proc int llMBIsSelected (string $OBJECT) { int $FOUND = 0 ; string $SELECTION[] = `ls -sl` ; for ($ELEMENT in $SELECTION) if ($ELEMENT == $OBJECT) $FOUND = 1 ; return $FOUND ; } ; // global proc llMBIsSelected ////////////////////////////////// // llMBEditWindowMenuitems // ////////////////////////////////// // // Creates the popupMenu's items. // // // <-- llMBEditWindowMenu // --> llMBGetWindowInformation // --> llMBChangeStatusColor // --> llMBChangeButtonLabel // --> llMBChooseButtonsColor // --> llMBTogglePlusMinusButtons // --> llMBUseCurrentSelection // --> llMBSaveButtonWindow // --> llMBPrintContents // ////////////////////////////////// global proc llMBEditWindowMenuitems (string $WINDOWNAME , string $LABEL , string $MENUNAME) { global string $LLMB_VERSION ; global string $WINDOW_INFO[] ; $WINDOW_INFO = `llMBGetWindowInformation $WINDOWNAME` ; popupMenu -e -dai $MENUNAME ; menuItem -p $MENUNAME -l "toggle window titlebar" -c ("window -e -tb (!`window -q -tb " + $WINDOWNAME + "`) -s (!`window -q -tb " + $WINDOWNAME + "`) " + $WINDOWNAME + "; llMBChangeStatusColor " + $WINDOWNAME + " 0 ;") ; menuItem -p $MENUNAME -l "adjust window size" -c ("llMBChangeNumericValues \"wh\" " + $WINDOWNAME) ; menuItem -p $MENUNAME -l "adjust window position" -c ("llMBChangeNumericValues \"tlc\" " + $WINDOWNAME) ; menuItem -p $MENUNAME -divider 1 ; menuItem -p $MENUNAME -l "change button label" -c ("llMBChangeButtonLabel " + $WINDOWNAME) ; menuItem -p $MENUNAME -l "change button color" -c ("llMBChooseButtonsColor " + $WINDOWNAME) ; menuItem -p $MENUNAME -l "toggle \"+/-\" buttons" -c ("llMBTogglePlusMinusButtons \"" + $WINDOWNAME + "\"; llMBChangeStatusColor " + $WINDOWNAME + " 0 ;") ; menuItem -p $MENUNAME -divider 1 ; menuItem -p $MENUNAME -l ("print contents (" + $WINDOW_INFO[1] + " nodes)") -c ("llMBPrintContents " + $WINDOWNAME) ; menuItem -p $MENUNAME -l "replace contents with current selection" -c ("llMBUseCurrentSelection " + $WINDOWNAME) ; menuItem -p $MENUNAME -divider 1 ; menuItem -p $MENUNAME -l "save window configuration" -c ("llMBSaveButtonWindow (\"" + $WINDOWNAME + "\")") ; menuItem -p $MENUNAME -l "delete saved window configuration" -en (`objExists ($WINDOWNAME + "_SCRIPTNODE")`) -c ("setAttr (\"" + $WINDOWNAME + "_SCRIPTNODE.scriptType\") 0 ; delete (\"" + $WINDOWNAME + "_SCRIPTNODE\") ; llMBChangeStatusColor (\"" + $WINDOWNAME + "\" , 0)") ; ; menuItem -p $MENUNAME -divider 1 ; menuItem -p $MENUNAME -l "unload window" -c ("deleteUI " + $WINDOWNAME ) -en (`objExists ($WINDOWNAME + "_SCRIPTNODE")`) ; menuItem -p $MENUNAME -l "load window" -subMenu 1 -pmc llMBWindowLoader -en (`llMBUnloadedWindowExists`) ; } ; // global proc llMBEditWindowMenuItems ////////////////////////////////// // llMBEditWindowMenu // ////////////////////////////////// // // Creates a popupMenu that will appear on MMB on the buttons, with features to edit the button window. // // // <-- llMBExecMakeButtonPlus // --> llMBEditWindowMenuitems // ////////////////////////////////// global proc llMBEditWindowMenu (string $WINDOWNAME , string $LABEL) { string $MENUNAME = `popupMenu` ; popupMenu -e -b 2 -pmc ("llMBEditWindowMenuitems (\"" + $WINDOWNAME + "\" , \"" + $LABEL + "\" , \"" + $MENUNAME + "\")") $MENUNAME ; } ; // global proc llMBEditWindowMenu ////////////////////////////////// // llMBCreateSelectMenuItems // ////////////////////////////////// // // Creates the popupMenu and its menu items. // // // <-- llMBExecMakeButtonPlus // --> llMBUpdateMenuItems // --> llMBWSetFocusOnModelPanel // --> llMBIsSelected // ////////////////////////////////// global proc llMBCreateSelectMenuItems ( string $FLAG , string $ITEMS[] ) { string $MENUNAME = `popupMenu` ; popupMenu -e -b 3 -pmc ("llMBUpdateMenuItems (\"" + $MENUNAME + "\")") $MENUNAME ; switch ($FLAG) { case "r" : menuItem -boldFont 1 -en 0 -l "select" ; break ; case "d" : menuItem -boldFont 1 -en 0 -l "remove from selection" ; break ; case "add" : menuItem -boldFont 1 -en 0 -l "add to selection" ; break ; } ; // switch ($FLAG) menuItem -divider 1 ; for ($ELEMENT in $ITEMS) menuItem -bld 0 -l $ELEMENT -c ("select -" + $FLAG + " " + $ELEMENT + " ; llMBWSetFocusOnModelPanel ;" ) -cb (llMBIsSelected ($ELEMENT)) ; } ; // global proc llMBCreateSelectMenuItems ////////////////////////////////////// // llMakeButtonConfirmReplacement // ////////////////////////////////////// // // Asks the user whether he wants to create a new window or replace the contents of the existing one. // // // <-- llMakeButtonPlus // ////////////////////////////////////// global proc string llMakeButtonConfirmReplacement () { global string $LLMB_VERSION ; string $REPLACE = "Replace Contents" ; string $CANCEL = "Cancel" ; string $RESULT = `confirmDialog -title ("llMakeButtonWindow v" + $LLMB_VERSION) -message "A window with the specified title already exists. What do you wish to do?" -button $REPLACE -button $CANCEL -defaultButton $REPLACE -cancelButton $CANCEL -dismissString $CANCEL` ; if ($RESULT == $REPLACE) $RESULT = 2 ; else $RESULT = 1 ; return $RESULT ; } ; // global proc llMakeButtonConfirmReplacement ////////////////////////////////// // llMakeButtonWindowExecute // ////////////////////////////////// // // Checks that some nodes are selected and that a valid name has been input. // // // --> llMakeButtonPlus // ////////////////////////////////// global proc llMakeButtonWindowExecute () { string $SELECTION[] = `ls -sl` ; if (`size $SELECTION` == 0) error ("select some nodes from the scene") ; else { string $INPUT_TEXT = `textField -q -tx TXTBUTTONWINDOW` ; if (`size $INPUT_TEXT` == 0) error ("enter a name for the button window") ; else llMakeButtonPlus ($INPUT_TEXT) ; } ; // else } ; // global proc llMakeButtonWindowExecute ////////////////////////////////// // llMakeButtonPlus // ////////////////////////////////// // // A button window is created, with its button labeled as specified. // // // <-- llMakeButtonWindowExecute // <-- triggered by the startup scriptNode of each saved window // --> llMBDoesWindowExist // --> llMakeButtonConfirmReplacement // --> llMBGetWindowInformation // --> llMBExecMakeButtonPlus // --> llMBEditWindowAspect // --> llMBChangeStatusColor // ////////////////////////////////// global proc llMakeButtonPlus (string $TXTNAMEBUTTON) { int $ROUTE = 0 ; // 0 : create button // 1 : cancel button creation // 2 : replace an existing button string $SELECTION[] = `ls -sl` ; string $WINDOWNAME ; string $WINDOW_INFO[] ; if (`llMBDoesWindowExist $TXTNAMEBUTTON`) { $ROUTE = `llMakeButtonConfirmReplacement` ; $WINDOWNAME = ("LLMBW_" + `substituteAllString $TXTNAMEBUTTON " " "_"`) ; $WINDOW_INFO = `llMBGetWindowInformation $WINDOWNAME` ; if ($ROUTE == 2) deleteUI $WINDOWNAME ; } ; // if (`llMBDoesWindowExist $TXTNAMEBUTTON`) if ($ROUTE != 1) if (`size $SELECTION` == 0) error ("select some nodes from the scene first") ; else { llMBExecMakeButtonPlus ($TXTNAMEBUTTON) ; if ($ROUTE == 2) { llMBEditWindowAspect ($WINDOWNAME , $WINDOW_INFO) ; llMBChangeStatusColor $WINDOWNAME 0 ; } ; // if ($ROUTE == 2) if (`window -ex llMakeButtonWindow`) deleteUI llMakeButtonWindow ; } ; // else (`size $SELECTION` == 0) } ; // global proc llMakeButtonPlus ////////////////////////////////// // llMakeButton // ////////////////////////////////// // // MAIN PROC // // A dialogue window is created, and the user can specify // the label for the button to be created. // // // --> llMakeButtonWindowExecute // ///////////////////////////////// global proc llMakeButton () { // // VARIABLES // global string $LLMB_VERSION ; int $WIDTH = 325 ; int $HEIGHT = 120 ; if (`window -ex llMakeButtonWindow` == 1) deleteUI llMakeButtonWindow ; window -title ("llMakeButtonWindow v" + $LLMB_VERSION) llMakeButtonWindow ; // // LAYOUTS // formLayout llMakeButtonWindowFormLayout ; formLayout llMakeButtonWindowLayoutElement1 ; text -l "Button Label : " llMBTextElement ; textField -tx "CONTROLS" -ec "llMakeButtonWindowExecute" TXTBUTTONWINDOW ; setParent .. ; button -l " CREATE BUTTON " -c "llMakeButtonWindowExecute" llMakeButtonWindowLayoutElement2 ; // // EDIT LAYOUTS // formLayout -e -attachForm llMBTextElement "top" 0 -attachNone llMBTextElement "bottom" -attachPosition llMBTextElement "left" 0 10 -attachPosition llMBTextElement "right" 0 35 -attachControl TXTBUTTONWINDOW "top" 0 llMBTextElement -attachForm TXTBUTTONWINDOW "bottom" 0 -attachPosition TXTBUTTONWINDOW "left" 0 35 -attachForm TXTBUTTONWINDOW "right" 0 llMakeButtonWindowLayoutElement1 ; formLayout -e -attachForm llMakeButtonWindowLayoutElement1 "top" 10 -attachForm llMakeButtonWindowLayoutElement1 "left" 5 -attachForm llMakeButtonWindowLayoutElement1 "right" 5 -attachNone llMakeButtonWindowLayoutElement1 "bottom" -attachControl llMakeButtonWindowLayoutElement2 "top" 10 llMakeButtonWindowLayoutElement1 -attachForm llMakeButtonWindowLayoutElement2 "left" 95 -attachForm llMakeButtonWindowLayoutElement2 "right" 95 -attachForm llMakeButtonWindowLayoutElement2 "bottom" 5 llMakeButtonWindowFormLayout ; // // SHOW WINDOW // window -e -minimizeButton 0 -maximizeButton 0 -wh $WIDTH $HEIGHT llMakeButtonWindow ; showWindow llMakeButtonWindow ; } ; // global proc llMakeButton //////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llMakeButton // ////////////////////////////////////////////////////////////////////////////////////////////////////