// llOrbitWindow // ////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@hotmail.com) // // Creation date : 28/I/2003 // // Main procedure : type "llOrbitWindow" in the Command Line or Script Editor // ////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // This script will create multiple duplicates of any object(s) in the scene and attach them to the specified // NURBS curve as a motion Path. All the objects will be orbiting the path at an exact distance and will // follow it in the specified time. The user can choose the objects to be either copies or duplicates, and to // duplicate it "raw" or with the input graph or with the input connections. It can be also chosen whether to // "follow" the path or not; and, if so, the disposition of the axes. // // This is a complete re-writing of a script I wrote 3 years ago. This new script has lots of new functions // (such as the random ones, and the instance / copy / ...). // // // // Enjoy!! // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// // chooseNextSelection // ////////////////////////////////// // // Given a list of objects and its size, the script will return randomly one of the objects in the list. // // <-- llOrbitWindowGo // ///////////////////////////////// global proc string chooseNextSelection (int $selectionSize , string $llOWObjects[]) { int $RND = rand (0, $selectionSize) ; return $llOWObjects[$RND] ; } ; // global proc chooseNextSelection ////////////////////////////////// // llOrbitGo // ////////////////////////////////// // // This is the "real" proc after the script. It will get the variables from the window, // then create its own variables, and run through a "for" that will create the satellites. // // The current keying preferences are saved in variables in order to have the keys "spline" // as default, and are later restored. // // All the satellites are parented to a new group, and at the end of the proc the new motion paths are selected. // // <-- llOrbitWindow // // --> chooseNextSelection // ///////////////////////////////// global proc llOrbitWindowGo () { // // gets the variables from the window // // names layout string $llOWCurve = `textFieldButtonGrp -q -tx textFieldButtonGrpCurveName` ; string $llOWObjects[] = `textScrollList -q -ai llOrbitObjectsList` ; // motion path layout float $llOWCycle = `floatFieldGrp -q -v1 llOrbitWindowFloatFieldCycle` ; int $llOWFollow = `checkBox -q -v llOrbitWindowCheckBoxFollow` ; string $llOWAimAxis = `radioCollection -q -sl llOWColeAimAxis` ; string $llOWUpAxis = `radioCollection -q -sl llOWColeUpAxis` ; int $llOWInverseAim = `checkBox -q -v llOWCheckBoxInverseAim` ; int $llOWInverseUp = `checkBox -q -v llOWCheckBoxInverseUp` ; switch ($llOWAimAxis) { case "llOWUpAxisX" : $llOWAimAxis = " x " ; break ; case "llOWUpAxisY" : $llOWAimAxis = " y " ; break; case "llOWUpAxisZ" : $llOWAimAxis = " z " ; break ; } ; // switch ($llOWAimAxis) switch ($llOWUpAxis) { case "llOWUpAxisX" : $llOWUpAxis = " x " ; break ; case "llOWUpAxisY" : $llOWUpAxis = " y " ; break; case "llOWUpAxisZ" : $llOWUpAxis = " z " ; break ; } ; // switch ($llOWUpAxis) // satellites layout int $llOWSatellites = `intFieldGrp -q -v1 llOrbitWindowIntFieldSatellites` ; string $llOWDuplicate = `radioCollection -q -sl llOWColeDuplicateType` ; int $llOWUpstreamChk = `checkBoxGrp -q -v1 llOWCheckBoxGraph` ; int $llOWInputChk = `checkBoxGrp -q -v2 llOWCheckBoxGraph` ; // // creates and updates $ERROR // we could filter the curve name to ensure there's no typing mistakes ... // int $ERROR = 0 ; if (`size $llOWCurve` == 0) $ERROR = 1 ; if (`size $llOWObjects` == 0) $ERROR = 1 ; // // creates and updates $DUP // string $DUP = "" ; if ($llOWDuplicate == "llOWDuplicateCopy") $DUP = "duplicate -rr " ; if ($llOWDuplicate == "llOWDuplicateInstance") $DUP = "instance " ; if ($llOWInputChk == 1) $DUP = "duplicate -rr -ic " ; if ($llOWUpstreamChk == 1) $DUP = "duplicate -rr -un " ; // // if there is no error, goes on // if ($ERROR == 1) error ("check your curve and objects") ; else { // variables int $I = 0 ; int $selectionSize = `size $llOWObjects` ; string $nextObject ; string $PathName ; string $motionPathsInScene[] = `ls -type motionPath` ; // stores the key settings and sets new settings string $oldKeyITT[] = `keyTangent -g -q -itt` ; string $oldKeyOTT[] = `keyTangent -g -q -ott` ; keyTangent -global -itt spline; keyTangent -global -itt spline; // creates an empty group Satellites[n] select -cl ; string $orbitGroup = `group -em -n "satellites1"` ; // goes into a FOR for the number of desired satellites for ($I = 1 ; $I <= $llOWSatellites ; $I++) { // chooses next object to be duplicated $nextObject = chooseNextSelection ($selectionSize , $llOWObjects) ; // makes the duplicate and stores the name string $newObject[] = `eval ($DUP + $nextObject)` ; // prepares the start and end number for the motion path float $factor = $llOWCycle / $llOWSatellites ; // creates the motion path select -r $newObject[0] $llOWCurve ; if ($llOWFollow == 1) { $PathName = `pathAnimation -fractionMode true -follow $llOWFollow -followAxis $llOWAimAxis -upAxis $llOWUpAxis -worldUpType "vector" -worldUpVector 0 1 0 -inverseUp $llOWInverseUp -inverseFront $llOWInverseAim -bank false -startTimeU ($I * $factor) -endTimeU ($llOWCycle + ($I * $factor))` ; } else { $PathName = `pathAnimation -fractionMode true -follow $llOWFollow -startTimeU ($I * $factor) -endTimeU ($llOWCycle + ($I * $factor))` ; } ; // makes the PRE and POST infinity linear eval ("setAttr " + $PathName + "_uValue.preInfinity 3" ); eval ("setAttr " + $PathName + "_uValue.postInfinity 3" ); // parents the object to the "satellites" group select -r $newObject[0] $orbitGroup ; parent ; } ; // for // restores the key settings keyTangent -global -itt $oldKeyITT[0] ; keyTangent -global -ott $oldKeyOTT[0] ; // selects only the new motion paths select -r `ls -type motionPath` ; select -tgl $motionPathsInScene ; } ; // else } ; // global proc llOrbitWindowGo ////////////////////////////////// // llOrbitFollowChange // ////////////////////////////////// // // This proc will run whenever the "follow" check box is modified, and will // enable/disable the appropiate portion of window // // <-- llOrbitWindow // ///////////////////////////////// global proc llOrbitFollowChange (int $VALUE) { // change the font of the text if ($VALUE == 0) { text -e -fn "obliqueLabelFont" llOWTextAimAxis ; text -e -fn "obliqueLabelFont" llOWTextUpAxis ; } else { text -e -fn "plainLabelFont" llOWTextAimAxis ; text -e -fn "plainLabelFont" llOWTextUpAxis ; } ; // enable or disable the other controls radioButton -e -en $VALUE llOWAimAxisX; radioButton -e -en $VALUE llOWAimAxisY; radioButton -e -en $VALUE llOWAimAxisZ; radioButton -e -en $VALUE llOWUpAxisX; radioButton -e -en $VALUE llOWUpAxisY; radioButton -e -en $VALUE llOWUpAxisZ; checkBox -e -en $VALUE llOWCheckBoxInverseAim ; checkBox -e -en $VALUE llOWCheckBoxInverseUp ; } ; // global proc llOrbitFollowChange ////////////////////////////////// // llOWGraph // ////////////////////////////////// // // This proc will run whenever the "graph" options are modified, and will // enable/disable the appropiate portion of window // // <-- llOrbitWindow // ///////////////////////////////// global proc llOWGraph (int $TYPE) { // gets the situation at the window int $upstreamChk = `checkBoxGrp -q -v1 llOWCheckBoxGraph` ; int $inputChk = `checkBoxGrp -q -v2 llOWCheckBoxGraph` ; if (($inputChk || $upstreamChk) == 0) // none is selected { radioButton -e -en 1 llOWDuplicateCopy ; radioButton -e -en 1 llOWDuplicateInstance; checkBoxGrp -e -en1 1 -en2 1 llOWCheckBoxGraph ; } else if ($inputChk == 1) { radioButton -e -en 0 llOWDuplicateCopy ; radioButton -e -en 0 llOWDuplicateInstance; checkBoxGrp -e -en1 0 llOWCheckBoxGraph ; } else if ($upstreamChk == 1) { radioButton -e -en 0 llOWDuplicateCopy ; radioButton -e -en 0 llOWDuplicateInstance; checkBoxGrp -e -en2 0 llOWCheckBoxGraph ; } ; } ; // global proc llOWGraph ////////////////////////////////// // isInList // ////////////////////////////////// // // This proc will return 1 if the given string is inside the given array, and 0 otherwise. // // <-- llOrbitWindow // ///////////////////////////////// global proc int isInList (string $NAME , string $LIST[] ) { // variable int $OKAY = 0 ; // goes through the list // if at any point the object is found to be in the list, $OKAY will be 1 for ($ELEMENT in $LIST) if ($ELEMENT == $NAME) $OKAY = 1 ; // returns the value of $OKAY return $OKAY ; } ; // global proc int isInList ////////////////////////////////// // llOrbitSelectedObject // ////////////////////////////////// // // This proc will modify the "orbiting objects" list as appropiate // // <-- llOrbitWindow // ///////////////////////////////// global proc llOrbitSelectedObject (int $TYPE) { // stores the selected names in a string array string $LIST[] = `ls -sl -type transform` ; // stores the current list in a string array string $OBJECTLIST[] = `textScrollList -q -ai llOrbitObjectsList` ; // stores the current selected list in a string array string $SELOBJECTLIST[] = `textScrollList -q -si llOrbitObjectsList` ; switch ($TYPE) { case 1 : // selected // if there's at least one selected object, puts them in the scroll list textScrollList -e -ra llOrbitObjectsList ; if (`size $LIST` > 0) for ($ELEMENT in $LIST) textScrollList -e -append $ELEMENT llOrbitObjectsList ; break ; case 2 : // add // if there's at least one selected object and is not already in the scroll list, // then puts it in the scroll list if (`size $LIST` > 0) for ($ELEMENT in $LIST) if (isInList ($ELEMENT , $OBJECTLIST) == 0) textScrollList -e -append $ELEMENT llOrbitObjectsList ; break ; case 3 : // remove for ($ELEMENT in $SELOBJECTLIST) textScrollList -e -ri $ELEMENT llOrbitObjectsList ; break ; } ; // switch ($TYPE) } ; // global proc llOrbitSelectedObject ////////////////////////////////// // llOrbitGetCurveName // ////////////////////////////////// // // This proc will be run whenever the "sel" button is activated. If the selected object is a NURBS curve, // its name will be written in the curve field. // // <-- llOrbitWindow // ///////////////////////////////// global proc llOrbitGetCurveName () { // gets selected curve objects string $LIST[] = `ls -sl -dag -type nurbsCurve` ; // checks that there is only one selected object if (`size $LIST` != 1) error ("select exactly one NURBS curve") ; else textFieldButtonGrp -e -tx `ls -sl` textFieldButtonGrpCurveName ; } ; // global proc llOrbitGetCurveName ////////////////////////////////// // llOrbitWindow // ////////////////////////////////// // // MAIN PROC // // Creates the main window. // ///////////////////////////////// global proc llOrbitWindow () { if (`window -ex llOrbitWindow` == true) deleteUI llOrbitWindow ; window -title "Orbit v2.0" -wh 340 625 -s 0 -minimizeButton 0 -maximizeButton 0 llOrbitWindow ; columnLayout llOrbitWindowMainStructure ; text "\n Orbit v2.0\n" ; separator -w 340 ; // names layout columnLayout -cat "left" 10 llOrbitWindowNamesLayout ; text "\nNames \n" ; textFieldButtonGrp -l "curve name : " -cw 1 90 -cw 2 180 -bl "sel" -bc "llOrbitGetCurveName" textFieldButtonGrpCurveName ; separator -style "none" -h 5 ; text " orbiting object(s) : " ; separator -style "none" -h 5 ; rowColumnLayout -nc 2 -co 1 "left" 40 -cw 1 215 -rat 1 "top" 0 -cw 2 80 -rat 2 "top" 1 llOrbitWindowNamesLayoutObjectsLayout ; textScrollList -w 150 -numberOfRows (5) -showIndexedItem 7 -ams 1 llOrbitObjectsList ; columnLayout llOrbitWindowNamesLayoutObjectsButtonsLayout ; button -w 80 -l "selected" -c "llOrbitSelectedObject (1)" ; button -w 80 -l "add" -c "llOrbitSelectedObject (2)" ; button -w 80 -l "remove" -c "llOrbitSelectedObject (3)" ; setParent llOrbitWindowMainStructure ; separator -w 340 -h 20 ; // path layout columnLayout -cat "left" 10 -rs 5 llOrbitWindowPathLayout ; text "Motion Path \n" ; floatFieldGrp -l "path time : " -el "frames" -nf 1 -v1 100 -cw 1 90 -cw 2 60 -pre 3 llOrbitWindowFloatFieldCycle ; columnLayout -co "left" 30 llOrbitWindowFollowLayout ; checkBox -l "follow" -v 1 -onc "llOrbitFollowChange (1)" -ofc "llOrbitFollowChange (0)" llOrbitWindowCheckBoxFollow ; separator -h 7 -style "none" ; text -l "aim axis :" llOWTextAimAxis ; rowColumnLayout -nc 3 -cat 1 "left" 30 -cat 2 "left" 15 llOrbitWindowAimAxis ; radioCollection llOWColeAimAxis ; radioButton -sl -l "X" llOWAimAxisX; radioButton -l "Y" llOWAimAxisY; radioButton -l "Z" llOWAimAxisZ; setParent .. ; text -l "up axis :" llOWTextUpAxis ; rowColumnLayout -nc 3 -cat 1 "left" 30 -cat 2 "left" 15 llOrbitWindowUpAxis ; radioCollection llOWColeUpAxis ; radioButton -l "X" llOWUpAxisX; radioButton -sl -l "Y" llOWUpAxisY; radioButton -l "Z" llOWUpAxisZ; setParent .. ; separator -style "none" -h 5 ; columnLayout -cat "left" 80 llOrbitWindowInverse ; checkBox -l "inverse aim" llOWCheckBoxInverseAim ; checkBox -l "inverse up" llOWCheckBoxInverseUp ; setParent llOrbitWindowMainStructure ; separator -w 340 -h 10 ; // multiple objects layout columnLayout -cat "left" 10 llOrbitWindowMultipleLayout ; text "\nSatellites \n" ; intFieldGrp -cw 1 140 -cw 2 50 -nf 1 -l "number of satellites : " -v1 10 llOrbitWindowIntFieldSatellites ; columnLayout -co "left" 30 -rs 5 llOrbitWindowDuplicateLayout ; text -l "duplicate type:" llOWTextDuplicate ; rowColumnLayout -nc 2 -cat 1 "left" 50 -cat 2 "left" 50 llOrbitWindowDuplicateType ; radioCollection llOWColeDuplicateType ; radioButton -sl -l "copy" llOWDuplicateCopy ; radioButton -l "instance" llOWDuplicateInstance; setParent .. ; setParent llOrbitWindowMultipleLayout ; checkBoxGrp -ncb 2 -l "" -la2 "upstream graph" "input connections" -cw 1 78 -cw 2 100 -onc "llOWGraph(1)" -ofc "llOWGraph(0)" llOWCheckBoxGraph ; setParent llOrbitWindowMainStructure ; separator -w 340 -h 10 ; // multiple objects layout columnLayout -cat "left" 110 llOrbitWindowButtonLayout ; separator -style "none" -h 12 ; button -l "GO !" -w 120 -c llOrbitWindowGo ; showWindow llOrbitWindow ; } ; // global proc llOrbitWindow ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llOrbitWindow // /////////////////////////////////////////////////////////////////////////////////////////////////////////////