////////////////////////////////////// //// James Deschenes - Look At Me //// //// Created Feb 21st, 2008 //// ////////////////////////////////////// // What does this do? // ------------------ // This script quickly aim all the selected lights to a target\ // // How do I use it? // ---------------- // 1. Select the object you want to target everything to // 2. Add to your selection the lights you want targeted to it // 3. Run the command "ldLookAtMe();" without the quotes. I would make a button out of it. ///////////////////////////////////////////// // Procedure to return the selected lights // ///////////////////////////////////////////// proc string[] getSelectedLights() { string $shape; string $selectedLights[]; string $select[] = `ls -sl -dag -leaf`; for ( $shape in $select ) { // Determine if this is a light. string $class[] = getClassification( `nodeType $shape` ); if ( ( `size $class` ) > 0 && ( "light" == $class[0] ) ) { $selectedLights[ `size $selectedLights` ] = $shape; } } // Result is an array of all lights included in // current selection list. return $selectedLights; } //////////////////// // Main Procedure // //////////////////// global proc jdLookAtMe() { string $selectedObjects[] = `ls -sl -dag -leaf`; string $targetShape[] = listTransforms($selectedObjects[0]); string $target = $targetShape[0]; string $lights[] = getSelectedLights(); ///////////////////////////////////////////////////////// // Lots of strange error checking on the target object // ///////////////////////////////////////////////////////// // 1. we start by making sure the user at least gave us// // two selected objects. // // // // 2. then we check what the first selected object // // (our target) is. // // // // 3. if the target object is a light, we remove it // // from our list of lights that need to be aimed // // (don't want to aim the light at it self. // // // // 4. we tell the user what's happening with a warning,// // becuase I it's probably not to often you want to // // target a light to a light // ///////////////////////////////////////////////////////// if (`size($selectedObjects)` >= 2) { string $targetClass[] = getClassification( `nodeType $selectedObjects[0]` ); // Check to see if the target is a light, if so, remove it from the list of objects to be aimed if ( ( "light" == $targetClass[0] ) && (`size($lights)` > 0) ) { warning("Target is a light, " + $target); stringArrayRemoveAtIndex(0, $lights); } } // Some more error checking here to make sure everything is still // working after playing arround with the arrays above if ( (`size($lights)` > 0) && (`size($selectedObjects)` >= 2) ) { /////////////////////////////////////////////// // Here is the start of everything important // /////////////////////////////////////////////// string $choice = `confirmDialog -title "Look At Me" -message "Keep lights contrained to target?" -button "Yes" -button "No" -defaultButton "Yes" -cancelButton "No" -dismissString "No"`; string $light; for ($light in $lights) { // We have been working only with the shape node so far // becuase we need to know what's a light and so on, so // in order to use an aim constraint, we need to get the // transform of that shape, which we do with the variable // below string $lightTransform[] = `listTransforms $light`; // Now we create the aim constraint between our target and light string $aimConstraint[] = `aimConstraint -aim 0 0 -1 $target $lightTransform[0]`; // If the user chose not to keep the aim constraints, then we delete them here if ($choice == "No") { delete $aimConstraint[0]; } } } else { /////////////////////////////////////////////////////////////// // If the selection is inadequate, throw up an error message // /////////////////////////////////////////////////////////////// error("You need to select at least one light and target"); } }