/////////////////////////////////////////// //// James Deschenes - Light Connector //// //// Created Feb 21st, 2008 //// /////////////////////////////////////////// ///////////////////////////////////////////// // 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; } ///////////////////////////////////////////////////////////////////// // Procedure which actually does the work of connecting everything // ///////////////////////////////////////////////////////////////////// proc connectLights() { string $lightList[] = getSelectedLights(); // This is a big list of attributes which so far are the only ones we really care about string $bigAttrList[] = {"intensity", "color", "coneAngle", "penumbraAngle", "dropoff", "ambientShade", "emitDiffuse", "emitSpecular", "shadowColor", "useRayTraceShadows", "lightRadius", "shadowRays", "rayDepthLimit", "useDepthMapShadows", "useMidDistDmap", "dmapFilterSize", "dmapResolution", "dmapBias", "dmapFocus", "dmapWidthFocus", "useDmapAutoFocus", "volumeShadowSamples", "fogShadowIntensity", "useOnlySingleDmap", "useX+Dmap", "useX-Dmap", "useY+Dmap", "useY-Dmap", "useZ+Dmap", "useZ-Dmap", "dmapLightName", "dmapSceneName", "dmapFrameExt", "fogIntensity", "fogSpread"}; // Make sure at least 2 lights are found by checking the returned array size to be at greater then or equal to 2 if (`size($lightList)` >= 2) { ////////////////// // MASTER LIGHT // ////////////////// string $masterLight = $lightList[0]; // Get the name of the master light stringArrayRemoveAtIndex(0, $lightList); // Remove the master light from a list of lights string $masterAttrList[]; string $masterBigAttrList[] = `listAttr -connectable -visible $masterLight`; // List all the attributes of our master light string $attr; for ($attr in $bigAttrList) { if (stringArrayContains($attr, $masterBigAttrList) == 1) { $masterAttrList[ `size $masterAttrList` ] = $attr; } } /////////////////// // CUTE PRINTOUT // /////////////////// print("Master light is " + $masterLight + " and of type " + `nodeType $masterLight` + "\n\n"); print("Master attributes are\n"); for ($attr in $masterAttrList) { print(" -" + $attr + "\n"); } print (" \n"); print("Slaves lights are\n"); for ($light in $lightList) { string $lightType = `nodeType $light`; print(" " + $light + " of type " + $lightType + "\n"); } print("\n"); //////////////// // SLAVE LOOP // //////////////// for ($light in $lightList) { //string $lightType = `nodeType $light`; string $attr; string $slaveBigAttrList[] = `listAttr -connectable -visible $light`; // List all the attributes of our slave light for ($attr in $slaveBigAttrList) { if (stringArrayContains($attr, $masterAttrList) == 1) { //print($light + " has matched " + $attr + "\n"); if (`connectionInfo -isDestination ($light + "." + $attr)` == 1) { print("Breaking previous connection found on " + $light + "." + $attr + "\n"); string $source = `connectionInfo -sourceFromDestination ($light + "." + $attr)`; disconnectAttr $source ($light + "." + $attr); } connectAttr -f ($masterLight + "." + $attr) ($light + "." + $attr); } } } ///////////////// // C'est Fini! // ///////////////// print("\n"); print("Light Connector Complete! Check script editor for details\n"); } else { // This error message should be self explanatory error("You must have at least two lights selected, a master and at least one other"); } } ///////////////////////////////////////////////////////////////////// // Main Procedure to create interface and run the other procedures // ///////////////////////////////////////////////////////////////////// global proc jdLightConnector() { print("\n\n-----Light Connector-----\n\n"); connectLights(); }