/////////////////////////////// // // llUpdateMotionTrail.mel // /////////////////////////////// // // Maya script file // /////////////////////////////// // // Author : Lluís Llobera // (lluisllobera@gmail.com) // // Creation date : 20/X/2004 // UPDATE 1.25 : 25/XI/2004 // UPDATE 1.5 : 27/XI/2004 // UPDATE 1.6 : 22/XII/2005 // UPDATE 1.65 : 28/XII/2005 // // Main procedure : type "llUpdateMotionTrail" in the Command Line or Script Editor // /////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // This script will create a window with the motion trails found in the scene. Within the window, // they can be updated, selected, and their visibility toggled. // // UPDATE 1.25 // Added a menuBar for the window, plus new menus for "draw style" and "toggle show frames" .. // // UPDATE 1.5 // Added a palettePort to allow the user to change the drawing overrides color of the motion trails. // // UPDATE 1.6 // Added fields for Start / End of the selected motion trails. Also added "create motion trail" option // in the main (clickable) menu. // // UPDATE 1.65 // Added "Delete" option in window's menu and in right-click popupmenu of the textScrollList. // Also got rid of the "Refresh Window" button in the buttons area -- the auto-refreshing seemed // to be working fine, and this way the window takes up less screen space ! // // NOTE // If you want, you can modify the numbers in the global int $INDEXES[]. The numbers I have assigned // are the ones I liked from Maya's default colorIndex. If you want some other colors, feel free // to change the numbers around. Just remember that the numbers in the colorIndex go from 1 to 32 ! // // Enjoy!! // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////// // global int $LLUDMT_INDEXES[] // //////////////////////////////////// // // Array of ints defining interesting (light) colors // from Maya's default colorIndex. // // <-- llUDMTTriggerPalette // <-- llUDMTDefinePalette // //////////////////////////////////// global int $LLUDMT_INDEXES[] = { 1 , 22 , 20 , 13 , 31 , 6 , 18 , 14 } ; ///////////////////////////////////////////// // global proc llUDMTChangeStartEndValues // ///////////////////////////////////////////// // // Deletes the highlighted motion trails // // // <-- llUpdateMotionTrail // ///////////////////////////////////////////// global proc llUDMTDeleteButton () { string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; for ($ELEMENT in $SELECTED) delete $ELEMENT ; llUDMTRefresh ; } ; // global proc llUDMTDeleteButton ///////////////////////////////////////////// // global proc llUDMTChangeStartEndValues // ///////////////////////////////////////////// // // Modifies the selected motion trails to // suit the new start / end values // // // <-- llUDMTSelectItem // ///////////////////////////////////////////// global proc llUDMTChangeStartEndValues (string $STARTEND) { float $NEWVALUE ; if ($STARTEND == "s") $NEWVALUE = `floatFieldGrp -q -v1 llUDMTStartFrame` ; else $NEWVALUE = `floatFieldGrp -q -v1 llUDMTEndFrame` ; string $CURRENTSELECTION[] = `ls -sl` ; string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; string $CHAINS[] ; string $TYPE ; int $ERROR ; int $ERRORSFOUND = 0 ; for ($ELEMENT in $SELECTED) { $ERROR = 1 ; $CHAINS = eval ("listRelatives -children " + $ELEMENT ) ; for ($CHAIN in $CHAINS) { $NEWCHAINS = eval ("listConnections -s 1 -d 0 " + $CHAIN) ; if ($ERROR == 1) { $TYPE = eval ("nodeType " + $NEWCHAINS[0]) ; if ($TYPE == "snapshot") { $ERROR = 0 ; eval ("setAttr " + $NEWCHAINS[0] + "." + $STARTEND + " " + $NEWVALUE) ; } ; // if } ; // if } ; // for $ERRORSFOUND = $ERRORSFOUND + $ERROR ; } ; // for if ($ERRORSFOUND > 0) error ("Some of the motion trails were not found.") ; } ; // global proc llUDMTChangeStartEndValues ///////////////////////////////////////////// // global proc llUDMTChangeStartEndFields // ///////////////////////////////////////////// // // Changes the start / end fields according to // the 1st of the selected motion trails // // // <-- llUDMTSelectItem // <-- llUDMTUpdateButton // ///////////////////////////////////////////// global proc llUDMTChangeStartEndFields () { string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; $CHAINS = eval ("listRelatives -children " + $SELECTED[0] ) ; $CHAINS = eval ("listConnections -s 1 -d 0 " + $CHAINS[0]) ; for ($CHAIN in $CHAINS) { $TYPE = eval ("nodeType " + $CHAIN) ; if ($TYPE == "snapshot") { floatFieldGrp -e -v1 (`getAttr ($CHAIN + ".s")`) llUDMTStartFrame ; floatFieldGrp -e -v1 (`getAttr ($CHAIN + ".e")`) llUDMTEndFrame ; } ; // if } ; // for } ; // global proc llUDMTChangeStartEndFields //////////////////////////////////////// // global proc llUDMTAutoRefresh // //////////////////////////////////////// // // Triggered when an object is created or renamed, // this proc refreshes the textScrollList but // keeps the selected index items // // // <-- llUpdateMotionTrail // --> llUDMTRefresh // --> llUDMTSelectItem // //////////////////////////////////////// global proc llUDMTAutoRefresh () { int $SELECTED_INDEXES[] = `textScrollList -q -sii llUDMTLayout1` ; llUDMTRefresh ; if (`size $SELECTED_INDEXES` > 0) { for ($INDEX in $SELECTED_INDEXES) eval ("textScrollList -e -sii " + $INDEX + " llUDMTLayout1") ; llUDMTSelectItem ; } ; } ; // global proc llUDMTNameChanged //////////////////////////////////////// // global proc llUDMTTriggerPalette // //////////////////////////////////////// // // Triggered when a color is chosen in the palettePort. // Changes the transform (in textScrollList) drawing overrides // status to 1, and its color depending on the // global int $INDEXES[] // // // <-- llUpdateMotionTrail // //////////////////////////////////////// global proc llUDMTTriggerPalette () { global int $LLUDMT_INDEXES[] ; int $COLORINDEX = eval ("palettePort -q -scc llUDMTPalette") ; string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; for ($ELEMENT in $SELECTED) { setAttr ($ELEMENT + ".overrideEnabled") 1 ; setAttr ($ELEMENT + ".overrideColor") $LLUDMT_INDEXES[$COLORINDEX] ; } ; // for } ; // global proc llUDMTTriggerPalette //////////////////////////////////////// // global proc llUDMTDefinePalette // //////////////////////////////////////// // // Defines the colors in the palette. If $ENABLE is 0 // they're all the colorIndex #3 (light gray by default), // if it's 1 then they're all colored according to // the global int $INDEXES[] // // // <-- llUpdateMotionTrail // <-- llUDMTSelectItem // <-- llUDMTRefresh // //////////////////////////////////////// global proc llUDMTDefinePalette (int $ENABLE) { // variables definition global int $LLUDMT_INDEXES[] ; int $I = 0 ; float $COLORARRAY[] ; // change color of cells depending on $ENABLE for ($INDEX in $LLUDMT_INDEXES) { if ($ENABLE == 1) $COLORARRAY = `colorIndex -q $INDEX` ; else $COLORARRAY = `colorIndex -q 3` ; palettePort -e -rgbValue $I $COLORARRAY[0] $COLORARRAY[1] $COLORARRAY[2] llUDMTPalette ; $I++ ; } ; // for // if there's anything selected check the first // item's override color and reflect it // if it's in the palette from the window string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; if (`size $SELECTED` > 0) if (`getAttr ($SELECTED[0] + ".overrideEnabled")` == 1) { int $COLOR = `getAttr ($SELECTED[0] + ".overrideColor")` ; for ($J = 0 ; $J <= (`size $LLUDMT_INDEXES`) ; $J++) if ($LLUDMT_INDEXES[$J] == $COLOR) palettePort -e -scc $J llUDMTPalette ; } ; // if // force redraw and enable / disable palette palettePort -e -enable $ENABLE -redraw llUDMTPalette ; } ; // global proc llUDMTDefinePalette ////////////////////////////////////// // global proc llUDMTDrawStyle // ////////////////////////////////////// // // Changes the draw style for the selected motion trails. // // // <-- llUpdateMotionTrail // ////////////////////////////////////// global proc llUDMTDrawStyle (string $ATTRIBUTE , int $STYLE) { string $CURRENTSELECTION[] = `ls -sl` ; string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; string $CHAINS[] ; string $TYPE ; int $ERROR ; int $ERRORSFOUND = 0 ; for ($ELEMENT in $SELECTED) { $ERROR = 1 ; $CHAINS = eval ("listRelatives -children " + $ELEMENT ) ; for ($CHAIN in $CHAINS) { if ($ERROR == 1) { $TYPE = eval ("nodeType " + $CHAIN) ; if ($TYPE == "snapshotShape") { $ERROR = 0 ; if ($ATTRIBUTE == "d") eval ("setAttr " + $CHAIN + ".d " + $STYLE) ; if ($ATTRIBUTE == "sf") eval ("setAttr " + $CHAIN + ".sf " + (!(`getAttr ($CHAIN + ".sf")`)) + " " + $STYLE) ; } ; // if } ; // if } ; // for $ERRORSFOUND = $ERRORSFOUND + $ERROR ; } ; // for if ($ERRORSFOUND > 0) error ("Some of the motion trails were not found.") ; select -r $CURRENTSELECTION ; } ; // global proc llUDMTDrawStyle ////////////////////////////////////// // global proc llUDMTUpdateButton // ////////////////////////////////////// // // Checks the selected items of the llUDMTLayout1, // fishes for "snapshot" node connections in their shape, // and then (if any were found) updates them, selecting them // and using the updateMotionTrail command. // // NOTE - Admittedly, this here could be a fairly shorter proc if // we selected the scrollList "names" (the transforms) directly, // but fishing for the snapshot and selecting it avoids having to // hihglight the transforms of the motionTrails, and I like it // better because it makes for less visual cluttering ... // // <-- llUpdateMotionTrail // --> llUDMTChangeStartEndFields // ////////////////////////////////////// global proc llUDMTUpdateButton () { string $CURRENTSELECTION[] = `ls -sl` ; string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; string $CHAINS[] ; string $TYPE ; int $ERROR ; int $ERRORSFOUND = 0 ; for ($ELEMENT in $SELECTED) { $ERROR = 1 ; $CHAINS = eval ("listRelatives -children " + $ELEMENT ) ; $CHAINS = eval ("listConnections -s 1 -d 0 " + $CHAINS[0]) ; for ($CHAIN in $CHAINS) { if ($ERROR == 1) { $TYPE = eval ("nodeType " + $CHAIN) ; if ($TYPE == "snapshot") { $ERROR = 0 ; select -r $CHAIN ; updateMotionTrail ; } ; // if } ; // if } ; // for $ERRORSFOUND = $ERRORSFOUND + $ERROR ; } ; // for if ($ERRORSFOUND > 0) error ("Some of the motion trails were not found.") ; llUDMTChangeStartEndFields ; select -r $CURRENTSELECTION ; } ; // global proc llUDMTUpdateButton ////////////////////////////////////// // global proc llUDMTSelectButton // ////////////////////////////////////// // // Selects the selected index in the llUDMTLayout1. // // <-- llUpdateMotionTrail // ////////////////////////////////////// global proc llUDMTSelectButton () { string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; select -r $SELECTED ; } ; // global proc llUDMTSelectButton ////////////////////////////////////// // global proc llUDMTShowButton // ////////////////////////////////////// // // Depending on the value of the given $VIS (1 or 0) // the selected elements in the llUDMTLayout1 // are either hidden or shown. // // <-- llUpdateMotionTrail // ////////////////////////////////////// global proc llUDMTShowButton (int $VIS) { string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; if ($VIS == 1) for ($ELEMENT in $SELECTED) eval ("showHidden -a " + $ELEMENT) ; else for ($ELEMENT in $SELECTED) eval ("setAttr " + $ELEMENT + ".v 0") ; } ; // global proc llUDMTSelectButton ////////////////////////////////////// // global proc llUDMTSelectItem // ////////////////////////////////////// // // When an item is selected, enable menus and buttons. // When it is un-selected, disable them. // // <-- llUpdateMotionTrail // <-- llUDMTAutoRefresh // --> llUDMTDefinePalette // --> llUDMTChangeStartEndFields // ////////////////////////////////////// global proc llUDMTSelectItem () { string $SELECTED[] = `textScrollList -q -si llUDMTLayout1` ; int $ENABLE ; if (`size $SELECTED` > 0) $ENABLE = 1 ; else $ENABLE = 0 ; floatFieldGrp -e -en $ENABLE llUDMTStartFrame ; floatFieldGrp -e -en $ENABLE llUDMTEndFrame ; for ($I = 1 ; $I <= 5 ; $I++) eval ("button -e -en " + $ENABLE + " llUDMTButton" + $I) ; for ($I = 1 ; $I <= 12 ; $I++) eval ("menuItem -e -en " + $ENABLE + " llUDMTMenu" + $I) ; for ($I = 0 ; $I <= 11 ; $I++) eval ("menuItem -e -en " + $ENABLE + " llUDMTMBMenu" + $I) ; llUDMTDefinePalette ($ENABLE) ; if ($ENABLE) llUDMTChangeStartEndFields ; } ; // global proc llUDMTSelectItem ////////////////////////////////////// // global proc llUDMTRefresh // ////////////////////////////////////// // // Refreshes the llUDMTLayout1 textScrollList. // // <-- llUpdateMotionTrail // <-- llUMDTDeleteButton // --> llUDMTAutoRefresh // --> llUDMTDefinePalette // ////////////////////////////////////// global proc llUDMTRefresh () { string $NAME[] ; textScrollList -e -ra llUDMTLayout1 ; string $MOTIONTRAILS[] = `ls -type snapshot` ; if ((`size $MOTIONTRAILS`) > 0) { for ($MOTIONTRAIL in $MOTIONTRAILS) { $NAME = eval ("listConnections -s 0 -d 1 " + $MOTIONTRAIL) ; textScrollList -e -fn "plainLabelFont" -append $NAME[0] llUDMTLayout1 ; } ; // for } ; // if for ($I = 1 ; $I <= 5 ; $I++) eval ("button -e -en 0 llUDMTButton" + $I) ; for ($I = 1 ; $I <= 12 ; $I++) eval ("menuItem -e -en 0 llUDMTMenu" + $I) ; for ($I = 0 ; $I <= 11 ; $I++) eval ("menuItem -e -en 0 llUDMTMBMenu" + $I) ; floatFieldGrp -e -en 0 llUDMTStartFrame ; floatFieldGrp -e -en 0 llUDMTEndFrame ; llUDMTDefinePalette 0 ; } ; // global proc llUDMTRefresh ////////////////////////////////////// // global proc llUpdateMotionTrail // ////////////////////////////////////// // // Creates the main window. // // --> llUDMTRefresh // --> llUDMTSelectItem // --> llUDMTShowButton // --> llUDMTSelectButton // --> llUDMTUpdateButton // --> llUDMTDrawStyle // --> llUDMTDefinePalette // --> llUDMTTriggerPalette // --> llUDMTChangeStartEndValues // --> llUDMTDeleteButton // ////////////////////////////////////// global proc llUpdateMotionTrail () { // variables definition string $VERSION = "1.65" ; int $WINWIDTH = 260 ; int $WINHEIGHT = 200 ; int $I = 1 ; // create window if (`window -ex llUDMTWindow`) deleteUI llUDMTWindow ; window -tb 1 -title ("llUpdateMotionTrail v" + $VERSION) -menuBar 1 llUDMTWindow ; menu -mn "c" -l "Motion Trail" llUDMTMenuSettings ; menuItem -en 1 -l "Create Motion Trail" -c ("doMotionTrail 1 { \"snapshot -motionTrail 1 -increment 1 -constructionHistory 1 -startTime `playbackOptions -query -min` -endTime `playbackOptions -query -max`\", \"point\", \"0\", \"force\"} ;") llUDMTMBMenuCreate ; menuItem -en 0 -l "Delete Motion Trail" -c "llUDMTDeleteButton" llUDMTMBMenu0 ; menuItem -en 0 -d 1 llUDMTMBMenu1 ; menuItem -en 0 -l "Update" -c "llUDMTUpdateButton" llUDMTMBMenu2 ; menuItem -en 0 -d 1 llUDMTMBMenu3 ; menuItem -en 0 -subMenu 1 -l "Draw style" llUDMTMBMenu4 ; menuItem -l "Line" -c "llUDMTDrawStyle d 0" llUDMTMBSubMenu1 ; menuItem -l "Locator" -c "llUDMTDrawStyle d 1" llUDMTMBSubMenu2 ; menuItem -l "Point" -c "llUDMTDrawStyle d 2" llUDMTMBSubMenu3 ; setParent -menu .. ; menuItem -en 0 -l "Toggle Show Frames" -c "llUDMTDrawStyle sf 0" llUDMTMBMenu5 ; menuItem -en 0 -d 1 llUDMTMBMenu6 ; menuItem -en 0 -l "Select" -c "llUDMTSelectButton" llUDMTMBMenu7 ; menuItem -en 0 -d 1 llUDMTMBMenu8 ; menuItem -en 0 -l "Show" -c "llUDMTShowButton 1" llUDMTMBMenu9 ; menuItem -en 0 -l "Hide" -c "llUDMTShowButton 0" llUDMTMBMenu10 ; menuItem -en 0 -d 1 llUDMTMBMenu11 ; menuItem -l "Refresh Window" -c "llUDMTRefresh" ; formLayout llUDMTFormLayout ; // define llUDMTLayout1 -- list of motion trails textScrollList -p llUDMTFormLayout -dcc llUDMTUpdateButton -ams 1 -selectCommand llUDMTSelectItem llUDMTLayout1 ; popupMenu ; menuItem -en 0 -l "Update" -c "llUDMTUpdateButton" llUDMTMenu1 ; menuItem -en 0 -d 1 llUDMTMenu2 ; menuItem -en 0 -subMenu true -l "Draw style" llUDMTMenu3 ; menuItem -l "Line" -c "llUDMTDrawStyle d 0" ; menuItem -l "Locator" -c "llUDMTDrawStyle d 1" ; menuItem -l "Point" -c "llUDMTDrawStyle d 2" ; setParent -menu .. ; menuItem -en 0 -l "Toggle Show Frames" -c "llUDMTDrawStyle sf 0" llUDMTMenu4 ; menuItem -en 0 -d 1 llUDMTMenu5 ; menuItem -en 0 -l "Select" -c "llUDMTSelectButton" llUDMTMenu6 ; menuItem -en 0 -d 1 llUDMTMenu7 ; menuItem -en 0 -l "Delete" -c "llUDMTDeleteButton" llUDMTMenu8 ; menuItem -en 0 -d 1 llUDMTMenu9 ; menuItem -en 0 -l "Show" -c "llUDMTShowButton 1" llUDMTMenu10 ; menuItem -en 0 -l "Hide" -c "llUDMTShowButton 0" llUDMTMenu11 ; menuItem -en 0 -d 1 llUDMTMenu12 ; menuItem -l "Refresh Window" -c "llUDMTRefresh"; // define llUDMTLayout2 -- buttons columnLayout -co "both" 5 -rs 2 -p llUDMTFormLayout -adj 1 llUDMTLayout2 ; button -en 0 -l "UPDATE" -c "llUDMTUpdateButton" llUDMTButton1 ; separator -h 7 ; rowColumnLayout -nc 2 -cw 1 50 -cw 2 50 ; floatFieldGrp -cat 1 "left" 1 -cat 2 "left" 5 -cal 2 "center" -cw 1 5 -adj 2 -l "S" -pre 0 -en 0 -v1 0 -cc ("llUDMTChangeStartEndValues (\"s\")") llUDMTStartFrame ; floatFieldGrp -cat 1 "left" 1 -cat 2 "left" 5 -cal 2 "center" -cw 1 5 -adj 2 -l "E" -pre 0 -en 0 -v1 0 -cc ("llUDMTChangeStartEndValues (\"e\")") llUDMTEndFrame ; setParent .. ; separator -h 7 ; rowColumnLayout -nc 2 -cw 1 50 -cw 2 50 ; button -l "LINE" -c "llUDMTDrawStyle d 0" llUDMTButton2 ; button -l "POINT" -c "llUDMTDrawStyle d 2" llUDMTButton3 ; setParent .. ; separator -style "none" -h 1 ; palettePort -w 100 -h 18 -dim 8 1 -colorEditable 0 -en 0 -cc llUDMTTriggerPalette llUDMTPalette ; llUDMTDefinePalette (0) ; separator -h 7 ; rowColumnLayout -nc 2 -cw 1 50 -cw 2 50 ; button -en 0 -l "SHOW" -c "llUDMTShowButton 1" llUDMTButton4 ; button -en 0 -l "HIDE" -c "llUDMTShowButton 0" llUDMTButton5 ; setParent .. ; // edit formLayout formLayout -e -attachForm llUDMTLayout1 "top" 5 -attachForm llUDMTLayout1 "bottom" 5 -attachForm llUDMTLayout1 "left" 5 -attachControl llUDMTLayout1 "right" 5 llUDMTLayout2 -attachForm llUDMTLayout2 "top" 5 -attachForm llUDMTLayout2 "bottom" 5 -attachNone llUDMTLayout2 "left" -attachForm llUDMTLayout2 "right" 5 llUDMTFormLayout ; // update and show window llUDMTRefresh ; scriptJob -p llUDMTWindow -event deleteAll llUDMTRefresh ; scriptJob -p llUDMTWindow -event NameChanged llUDMTAutoRefresh ; scriptJob -p llUDMTWindow -event DagObjectCreated llUDMTAutoRefresh ; window -e -wh $WINWIDTH $WINHEIGHT llUDMTWindow ; showWindow llUDMTWindow ; } ; // global proc llUpdateMotionTrail ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llUpdateMotionTrail.mel // /////////////////////////////////////////////////////////////////////////////////////////////////////////////