// llScaleKey // ////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@hotmail.com) // // Creation date : 14/IV/2003 // UPDATE 1.1 : 18/IV/2003 // UPDATE 1.2 : 24/IV/2003 // UPDATE 1.3 : 7/VIII/2003 // UPDATE 1.5 : 31/III/2005 // // Main procedure : type "llScaleKey" in the Command Line or Script Editor // ////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // This script will allow the user to scale keys selected in the Graph Editor, either in Value or Time. // // UPDATE 1.1 // Now the user can choose to scale from zero, which is how it was set in version 1.0, or to scale // from the minimum/maximum selected value / time. // // UPDATE 1.2 // Now there's two little buttons labeled "R" that will reset back to 100.0 the value of either Time // or Value. // // UPDATE 1.3 // Now there's another radioButton that enables the user to scale keys from the central value of the selection. // The window has grown a little bit. // // UPDATE 1.5 // The user can specify exact values for the "scale from" points, both in time and value // // UPDATE 1.51 // Added popupmenus to have number presets, for faster interaction // // // Enjoy!! // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// // llKSWCreatePopupMenu // ////////////////////////////////// // // Creates a popupmenu to change the floatField values according to // specified presets. There's also an "invert" menuItem that inverts // the floatField's current value. // // <-- llScaleKeyPress // <--> llScaleKeyValue // ///////////////////////////////// global proc llKSWCreatePopupMenu (string $CONTROL) { int $VALUES[] = {2 , 5 , 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 , 120 , 150 , 180 , 200 } ; $MENU = `popupMenu` ; menuItem -p $MENU -label "positive" -subMenu 1 ; for ($VALUE in $VALUES) menuItem -l $VALUE -c ("floatFieldGrp -e -v1 " + $VALUE + " " + $CONTROL) ; menuItem -p $MENU -label "negative" -subMenu 1 ; for ($VALUE in $VALUES) menuItem -l (-1 * $VALUE) -c ("floatFieldGrp -e -v1 " + (-1 * $VALUE) + " " + $CONTROL) ; menuItem -p $MENU -divider 1 ; menuItem -p $MENU -l "invert" -c ("floatFieldGrp -e -v1 (`floatFieldGrp -q -v1 " + $CONTROL + "` * -1) " + $CONTROL) ; } ; // global proc llKSWCreatePopupMenu ////////////////////////////////// // llScaleKeyValue // ////////////////////////////////// // // Whenever the "SPECIFY" radio button changes value, // this proc updates the "enable" state of the corresponding floatFields // // <-- llScaleKeyPress // <--> llScaleKeyValue // ///////////////////////////////// global proc llKeyScaleWindowSpecifyChanged () { int $STATE = `radioButton -q -sl llKeySPECIFY` ; floatFieldGrp -e -en ($STATE) llKSWSPECIFYVALUE ; floatFieldGrp -e -en ($STATE) llKSWSPECIFYTIME ; } ; // global proc llKeyScaleWindowSpecifyChanged ////////////////////////////////// // llScaleKeyValue // ////////////////////////////////// // // Gets and returns the lowest/greatest selected keyframe value, // depending of the value of $FROM // // <-- llScaleKeyPress // <--> llScaleKeyValue // ///////////////////////////////// global proc float llScaleKeyValue (string $FROM , float $SPECIFY , string $TYPE) { // variables float $KEYVALUE ; // float to be returned to llScaleKeyPress float $VALUES[] = eval ("keyframe -q -" + $TYPE + "c") ; // value of the selected keyframes // depending of the value of $FROM, // a different value is assigned to $KEYVALUE switch ($FROM) { case "llKeyZERO" : // wanted scale from ZERO $KEYVALUE = 0.0 ; break ; case "llKeyMIN" : // wanted scale from MINIMUM KEY VALUE $KEYVALUE = $VALUES[0] ; for ($ELEMENT in $VALUES) $KEYVALUE = `min $KEYVALUE $ELEMENT` ; break ; case "llKeyMAX" : // wanted scale from MAXIMUM KEY VALUE $KEYVALUE = $VALUES[0] ; for ($ELEMENT in $VALUES) $KEYVALUE = `max $KEYVALUE $ELEMENT` ; break ; case "llKeySPECIFY" : // wanted scale from MAXIMUM KEY VALUE $KEYVALUE = $SPECIFY ; break ; case "llKeyCENTER" : // wanted scale from VALUE HALFWAY BETWEEN MAXIMUM AND MINIMUM $KEYVALUE = (`eval ("llScaleKeyValue (\"llKeyMIN\" , \"0\" , \"" + $TYPE + "\")")` + `eval ("llScaleKeyValue (\"llKeyMAX\" , \"0\" , \"" + $TYPE + "\")")` ) / 2 ; break ; } ; // switch $FROM return $KEYVALUE ; } ; // global proc float llScaleKeyValue ////////////////////////////////// // llScaleKeyPress // ////////////////////////////////// // // Gets the variables from the window and parses them into // the string to be evaluated. // // <-- llScaleKey // --> llScaleKeyValue // ///////////////////////////////// global proc llScaleKeyPress () { // variables float $VALUE = `floatFieldGrp -q -v1 llKeyScaleWindowScaleValueField` / 100 ; float $TIME = `floatFieldGrp -q -v1 llKeyScaleWindowScaleTimeField` / 100 ; string $FROM = `radioCollection -q -sl llKeyScaleWindowFromCollection` ; float $SPECIFYVALUE = `floatFieldGrp -q -v1 llKSWSPECIFYVALUE` ; float $SPECIFYTIME = `floatFieldGrp -q -v1 llKSWSPECIFYTIME` ; // figure out "scale from" values float $TIMESCALE = llScaleKeyValue ($FROM , $SPECIFYTIME , "t") ; float $VALUESCALE = llScaleKeyValue ($FROM , $SPECIFYVALUE , "v") ; // key scale eval ("scaleKey -iub false -ts " + $TIME + "-tp " + $TIMESCALE + " -fs " + $TIME + " -fp " + $VALUESCALE + " -vs " + $VALUE + " -vp " + $VALUESCALE + " -animation keys") ; } ; // global proc llScaleKeyPress ////////////////////////////////// // llScaleKey // ////////////////////////////////// // // MAIN PROC // // Draws the window with the scale fields. // // --> llScaleKeyPress // ///////////////////////////////// global proc llScaleKey () { string $VERSION = "1.51" ; int $WIDTH = 200 ; int $HEIGHT = 180 ; if (`window -ex llScaleKeyWindow`) deleteUI llScaleKeyWindow ; window -s 0 -tb 1 -t ("llScaleKey v" + $VERSION) llScaleKeyWindow ; columnLayout llKeyScaleWindowEstructura ; separator -style "none" -h 7 ; rowColumnLayout -nc 2 -cw 1 145 -cw 2 20 llKeyScaleWindowEstructuraFields ; floatFieldGrp -cw 1 70 -cw 2 44 -l "Value :" -el "%" -v1 100 llKeyScaleWindowScaleValueField ; llKSWCreatePopupMenu ("llKeyScaleWindowScaleValueField") ; button -l "R" -c "floatFieldGrp -e -v1 100.0 llKeyScaleWindowScaleValueField" llKeyScaleWindowResetValueButton ; llKSWCreatePopupMenu ("llKeyScaleWindowScaleValueField") ; floatFieldGrp -cw 1 70 -cw 2 44 -l "Time :" -el "%" -v1 100 llKeyScaleWindowScaleTimeField ; llKSWCreatePopupMenu ("llKeyScaleWindowScaleTimeField") ; button -l "R" -c "floatFieldGrp -e -v1 100.0 llKeyScaleWindowScaleTimeField" llKeyScaleWindowResetTimeButton ; llKSWCreatePopupMenu ("llKeyScaleWindowScaleTimeField") ; setParent llKeyScaleWindowEstructura ; separator -style "none" -h 5 ; columnLayout -cat "left" 15 llKeyScaleWindowFromPreLayout ; radioCollection llKeyScaleWindowFromCollection ; columnLayout -cat "left" 48 llKeyScaleWindowFromLayout2 ; radioButton -sl -l "ZERO" llKeyZERO ; setParent .. ; rowColumnLayout -nc 3 -cw 1 48 -cw 2 72 llKeyScaleWindowFromLayout1 ; radioButton -l "MIN" -cl llKeyScaleWindowFromCollection llKeyMIN ; radioButton -l "CENTER" -cl llKeyScaleWindowFromCollection llKeyCENTER ; radioButton -l "MAX" -cl llKeyScaleWindowFromCollection llKeyMAX ; setParent llKeyScaleWindowEstructura ; columnLayout -cat "left" 63 llKeyScaleWindowFromLayout3 ; radioButton -l "SPECIFY" -cc llKeyScaleWindowSpecifyChanged -cl llKeyScaleWindowFromCollection llKeySPECIFY ; setParent llKeyScaleWindowEstructura ; separator -style "none" -h 1 ; rowColumnLayout -numberOfColumns 2 -cw 1 95 ; floatFieldGrp -cl2 "right" "left" -cw 1 50 -cw 2 40 -l "V :" -en 0 llKSWSPECIFYVALUE ; floatFieldGrp -cl2 "right" "left" -cw 1 30 -cw 2 40 -l "T :" -en 0 llKSWSPECIFYTIME ; setParent llKeyScaleWindowEstructura ; separator -style "none" -h 5 ; columnLayout -cat "left" 41 llKeyScaleWindowButtonLayout ; button -l "GO !" -w 107 -c llScaleKeyPress llKeyScaleWindowButton ; showWindow llScaleKeyWindow ; window -e -wh $WIDTH $HEIGHT llScaleKeyWindow ; } ; // global proc llScaleKey ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llScaleKey // /////////////////////////////////////////////////////////////////////////////////////////////////////////////