////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@hotmail.com) // // Creation date : 3/VI/2004 // Update 1.1 : 9/VI/2004 // Update 1.15 : 9/VI/2004 // Update 1.5 : 10/VI/2004 // Update 1.6 : 15/VI/2004 // Update 1.7 : 17/VI/2004 // Update 1.8 : 26/VI/2004 // // Main procedure : type "llShowAnimCurves" in the Command Line or Script Editor // ////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // // This script will enable the user to isolate in the Graph Editor the translate, rotate, scale and // dynamic att curves in the Graph Editor. Thanks to Stephane Marino for the idea !! // // VERSION 1.1 // Now the script includes the "active tool" option, and also updates the Graph Editor when the // selection changes // // VERSION 1.15 // Minor bug corrected... now Maya does not crash :-) // // VERSION 1.5 // XYZ checkboxes added // // VERSION 1.6 // "from Channel Box" button added // // VERSION 1.7 // "Show" button added // // VERSION 1.8 // "FRAME" button added. Had to invent a long way around for the new function since the // selectonConnection command does not return channel names if objects are selected // in the graphEditor1FromOutliner... // // // Enjoy!! // //////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// // llSACNameIsChannel // /////////////////////////////////////////// // // Returns 0 if the input name is an object, // or 1 if it is an attribute // // // <-- llSACFilterChannels // /////////////////////////////////////////// global proc int llSACNameIsChannel (string $NAME) { int $RETURN = 0 ; string $SUBSTRING ; for ($I = 1 ; $I <= (`size $NAME` - 1) ; $I++) { $SUBSTRING = eval ("substring " + $NAME + " " + $I + " " + $I ) ; if ($SUBSTRING == ".") $RETURN = 1 ; } ; // for return $RETURN ; } ; // global proc int llSACIntNameIsChannel ////////////////////////////////////////// // llSACFilterChannels // ////////////////////////////////////////// // // Goes through the names input by $CHANNELS // and checks if they are channels or objects. // If they are objects, their keyable attributes // are added to $CHANNELS. // // // <-- llSACFitCurvesWithinRange // --> llSACNameIsChannel // /////////////////////////////////////////// global proc string[] llSACFilterChannels (string $CHANNELS[]) { int $SIZE = `size $CHANNELS` ; if ($SIZE > 0) { for ($I = 0 ; $I<= $SIZE-1 ; $I++) { if (!`llSACNameIsChannel ($CHANNELS[$I])`) { string $ATTS[] = `listAttr -k $CHANNELS[$I]` ; for ($ATT in $ATTS) { string $CURVENAME[] = eval ("listConnections -type animCurve " + $CHANNELS[$I] + "." + $ATT) ; if (`size $CURVENAME` > 0) $CHANNELS[(`size $CHANNELS`)] = $CHANNELS[$I] + "." + $ATT ; } ; // for ($ATT in $ATTS) } ; // if } ; // for } ; // if ($SIZE > 0) return $CHANNELS ; } ; // global proc llSACFilterChannels /////////////////////////////////////////// // llSACFitCurvesWithinRange // /////////////////////////////////////////// // // Frames the currently vsible curves within the current // animation range in the Graph Editor // // // <-- llShowAnimCurves // --> llSACFilterChannels // /////////////////////////////////////////// global proc llSACFitCurvesWithinRange () { string $CHANNELS[] = `selectionConnection -q -obj graphEditor1FromOutliner` ; $CHANNELS = `llSACFilterChannels ($CHANNELS)` ; int $SIZECHANNELS = `size $CHANNELS` ; float $MAXVALUE = 0 ; float $MINVALUE = 0 ; int $INIT = 0 ; // 0 : first evaluated key ; 1 : rest float $STARTTIME = `playbackOptions -query -minTime` ; float $ENDTIME = `playbackOptions -query -maxTime` ; for ($COUNT = 0 ; $COUNT < $SIZECHANNELS ; $COUNT++) { int $KEYS = `keyframe -q -kc ($CHANNELS[$COUNT])` ; string $CURVENAME[] = eval ("listConnections -type animCurve " + $CHANNELS[$COUNT]) ; for ($I = 0 ; $I <= $KEYS-1 ; $I++) { float $KEYTIME = eval ("getAttr " + $CURVENAME[0] + ".ktv[" + $I + "].kt") ; float $KEYVALUE = eval ("getAttr " + $CURVENAME[0] + ".ktv[" + $I + "].kv") ; if (($KEYTIME >= $STARTTIME) && ($KEYTIME <= $ENDTIME)) { if ($INIT == 0) { $MINVALUE = $KEYVALUE ; $MAXVALUE = $KEYVALUE ; $INIT = 1 ; } ; if ($KEYVALUE > $MAXVALUE) $MAXVALUE = $KEYVALUE ; if ($KEYVALUE < $MINVALUE) $MINVALUE = $KEYVALUE ; } ; // if } ; // for } ; // for ($CHANNEL in $CHANNELS) if ($INIT == 1) { float $VALUEDIFFERENCE = (abs ($MAXVALUE - $MINVALUE) * 0.1 ) ; float $TIMEDIFFERENCE = (abs ($STARTTIME - $ENDTIME) * 0.1 ) ; eval ("animView -startTime " + ($STARTTIME - $TIMEDIFFERENCE ) + " -endTime " + ($ENDTIME + $TIMEDIFFERENCE) + " -minValue " + ($MINVALUE - $VALUEDIFFERENCE) + " -maxValue " + ($MAXVALUE + $VALUEDIFFERENCE)+ " graphEditor1GraphEd ;" ) ; } ; // if ($INIT == 1) } ; // global proc llSACFitCurvesWithinRange /////////////////////////////////////////// // llSACEnable // /////////////////////////////////////////// // // Modifies the enabled state of the specified checkBox // // <-- llSACISolateCurves // /////////////////////////////////////////// global proc llSACEnable (string $CHKBOXNAME , int $ENABLE) { eval ("checkBox -e -en " + $ENABLE + " " + $CHKBOXNAME) ; } ; // global proc llSACEnable /////////////////////////////////////////// // llSACParse // /////////////////////////////////////////// // // Gathers the values from the main window // // <-- llShowAnimCurves // --> llSACISolateCurves // --> llSACScriptJobCreate // /////////////////////////////////////////// global proc llSACParse (string $CTOOL) { // variable definition string $TYPE = `optionMenu -q -v llSACMenu` ; if ($CTOOL != "") $TYPE = $CTOOL ; llSACIsolateCurves ($TYPE) ; } ; // llSACParse /////////////////////////////////////////// // llSACIsolateCurves // /////////////////////////////////////////// // // Isolates the specified curves // // <-- llSACParse // <-- llShowAnimCurves // /////////////////////////////////////////// global proc llSACIsolateCurves (string $TYPE) { int $ENX = `checkBox -q -v llSACX` ; int $ENY = `checkBox -q -v llSACY` ; int $ENZ = `checkBox -q -v llSACZ` ; string $SELECTION[] = `ls -sl` ; string $ATTS[] ; switch ($TYPE) { case "All" : llSACEnable ("llSACX" , 0) ; llSACEnable ("llSACY" , 0) ; llSACEnable ("llSACZ" , 0) ; selectionConnection -e -clr graphEditor1FromOutliner ; for ($ELEMENT in $SELECTION) eval ("selectionConnection -e -obj (\"" + $ELEMENT + "\") graphEditor1FromOutliner ") ; break ; // case "All" case "Translate" : llSACEnable ("llSACX" , 1) ; llSACEnable ("llSACY" , 1) ; llSACEnable ("llSACZ" , 1) ; selectionConnection -e -clr graphEditor1FromOutliner ; for ($ELEMENT in $SELECTION) if (`objExists ($ELEMENT + ".t")`) { if ($ENX) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".tx\") graphEditor1FromOutliner") ; if ($ENY) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".ty\") graphEditor1FromOutliner") ; if ($ENZ) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".tz\") graphEditor1FromOutliner") ; } ; break ; // case "Translate" case "Rotate" : llSACEnable ("llSACX" , 1) ; llSACEnable ("llSACY" , 1) ; llSACEnable ("llSACZ" , 1) ; selectionConnection -e -clr graphEditor1FromOutliner ; for ($ELEMENT in $SELECTION) if (`objExists ($ELEMENT + ".r")`) { if ($ENX) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".rx\") graphEditor1FromOutliner") ; if ($ENY) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".ry\") graphEditor1FromOutliner") ; if ($ENZ) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".rz\") graphEditor1FromOutliner") ; } ; break ; // case "Rotate" case "Scale" : llSACEnable ("llSACX" , 1) ; llSACEnable ("llSACY" , 1) ; llSACEnable ("llSACZ" , 1) ; selectionConnection -e -clr graphEditor1FromOutliner ; for ($ELEMENT in $SELECTION) if (`objExists ($ELEMENT + ".s")`) { if ($ENX) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".sx\") graphEditor1FromOutliner") ; if ($ENY) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".sy\") graphEditor1FromOutliner") ; if ($ENZ) eval ("selectionConnection -e -obj (\"" + $ELEMENT + ".sz\") graphEditor1FromOutliner") ; } ; break ; // case "Scale" case "Dynamic Atts" : llSACEnable ("llSACX" , 0) ; llSACEnable ("llSACY" , 0) ; llSACEnable ("llSACZ" , 0) ; selectionConnection -e -clr graphEditor1FromOutliner ; for ($ELEMENT in $SELECTION) { $ATTS = eval ("listAttr -ud " + $ELEMENT ) ; for ($ATT in $ATTS) { eval ("selectionConnection -e -obj (\"" + $ELEMENT + "." + $ATT + "\") graphEditor1FromOutliner") ; } ; } ; // for ($ELEMENT in $SELECTION) break ; // case "Dynamic Atts" case "Active Tool" : llSACEnable ("llSACX" , 1) ; llSACEnable ("llSACY" , 1) ; llSACEnable ("llSACZ" , 1) ; selectionConnection -e -clr graphEditor1FromOutliner ; llSACScriptJobExecute ; break ; // case "Active Tool" case "from Channel Box" : llSACEnable ("llSACX" , 0) ; llSACEnable ("llSACY" , 0) ; llSACEnable ("llSACZ" , 0) ; string $CHANNELS[] = `channelBox -q -sma mainChannelBox`; if (! size($CHANNELS)) error "No channels selected."; else { selectionConnection -e -clr graphEditor1FromOutliner; for ($ELEMENT in $SELECTION) { for ($CHANNEL in $CHANNELS) if (`objExists ($ELEMENT + "." + $CHANNEL)`) selectionConnection -e -obj ($ELEMENT + "." + $CHANNEL) graphEditor1FromOutliner ; } ; // for ($ELEMENT in $SELECTION) } ; // else break ; // case "From Channel Box" } ; // switch ($TYPE) } ; // global proc llSACIsolateCurves /////////////////////////////////////////// // llSACScriptJobExecute // /////////////////////////////////////////// // // Execution of the script job // // <-- llSACScriptJobCreate // --> llSACParse // /////////////////////////////////////////// global proc llSACScriptJobExecute () { string $OPTION = `optionMenu -q -v llSACMenu` ; string $TOOL = `currentCtx` ; string $TYPE ; switch ($TOOL) { case "moveSuperContext" : $TYPE = "Translate" ; break ; case "RotateSuperContext" : $TYPE = "Rotate" ; break ; case "scaleSuperContext" : $TYPE = "Scale" ; break ; default : $TYPE = "" ; break ; } ; // $TOOL if (($TYPE != "") && ($OPTION == "Active Tool")) eval ("llSACParse (\"" + $TYPE + "\")") ; } ; // global proc llSACScriptJobExecute /////////////////////////////////////////// // llSACScriptJobCreate // /////////////////////////////////////////// // // Creates the script jobs : // one for "active tool", one for "selection change" // // <-- llShowAnimCurves // --> llSACScriptJobExecute // --> llSACParse // /////////////////////////////////////////// global proc llSACScriptJobCreate () { scriptJob -p llShowAnimCurves -e ToolChanged llSACScriptJobExecute ; scriptJob -p llShowAnimCurves -e SelectionChanged ("llSACIsolateCurves (\"\")") ; } ; // global proc llSACScriptJobCreate /////////////////////////////////////////// // llShowAnimCurves // /////////////////////////////////////////// // // MAIN PROC // // Creates the main window // // --> llSACParse // --> llSACScriptJobCreate // --> llSACIsolateCurves // --> llSACFitCurvesWithinRange // /////////////////////////////////////////// global proc llShowAnimCurves () { if (`window -ex llShowAnimCurves`) deleteUI llShowAnimCurves ; window -title "llShowAnimationCurves v1.8" llShowAnimCurves ; columnLayout -adj 1 -rs 5 ; rowColumnLayout -nc 10 -cw 1 5 -cw 2 45 -cw 3 5 -cat 4 "left" 3 -cat 5 "left" 15 -cw 5 25 -cw 6 30 -cw 7 30 -cw 8 25 -cw 9 15 -cw 10 65 ; separator -style "none" -hr 0 ; button -l "Show" -c ("llSACParse (\"\")") ; separator -style "none" -hr 0 ; optionMenu -cc ("llSACParse (\"\")") llSACMenu ; menuItem -label "All" ; menuItem -label "Translate" ; menuItem -label "Rotate" ; menuItem -label "Scale" ; menuItem -label "Dynamic Atts" ; menuItem -label "from Channel Box" ; menuItem -label "Active Tool" ; separator -hr 0 ; checkBox -w 30 -l "X" -v 1 -cc ("llSACParse (\"\")") -en 0 llSACX ; checkBox -w 30 -l "Y" -v 1 -cc ("llSACParse (\"\")") -en 0 llSACY ; checkBox -w 30 -l "Z" -v 1 -cc ("llSACParse (\"\")") -en 0 llSACZ ; separator -hr 0 -style "in" ; button -l "FRAME" -c ("llSACFitCurvesWithinRange") ; window -e -rtf 1 llShowAnimCurves ; window -e -w 360 -s 0 llShowAnimCurves ; showWindow llShowAnimCurves ; llSACScriptJobCreate ; } ; // global proc llShowAnimCurves //////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llShowAnimCurves // ////////////////////////////////////////////////////////////////////////////////////////////////////