////////////////////////////////////////////////////////////////////// // // drLocalWorld: // // This script will create a local world relationship for controls // on a rig. So for example, an IK arm doesn't have to follow with // the back, but you can set it to. // // Use: Source drLocalWorld and type it in the command line. Select // the control which will serve as the local (IE. upper back for // the arm, arm for the hand, etc.)and then the control // that will be setup for local/world to create local and world // locators and make connections for the constraints. A worldLoc // must exist, and you must have a group above the controller you // wish to have the local/world for and the prefix has to be the // same. Example: handControl -----> handControlGrp - you enter Grp. // Use group2Self to create a group with the same position. // // Author: David Rhodes // Contact: digitalsandwichinc@hotmail.com // ////////////////////////////////////////////////////////////////////// // Inputs/Outputs: None // This procedure is the UI, featuring a button that will actually setup the constraints global proc drLocalWorld () { if (`window -q -ex LWWindow`) deleteUI LWWindow; window -t "DRhodes' Local World" LWWindow; menuBarLayout; menu -label "Help"; menuItem -l "Help..." -c ("LWHelp"); columnLayout -adjustableColumn true; frameLayout -label "Step 1: Ensure A World Locator Exists" -labelAlign "bottom" -borderStyle "in"; columnLayout; text " "; button -w 120 -l "Create World Locator" -c "CreateLocator; rename locator1 worldLoc;"; text " "; text "Parent this locator to the rig's main transform node"; text "(Only one worldLoc is needed)"; text " "; setParent ..; setParent ..; frameLayout -label "Step 2: Ensure there is a group above object" -labelAlign "bottom" -borderStyle "in"; columnLayout; text " "; text "Select object to group to self"; text "(If no group padding already exists)"; text " "; button -w 120 -l "Group to Self" -c group2Self; text " "; setParent ..; setParent ..; frameLayout -label "Step 3: Insert Name of Group Suffix" -labelAlign "bottom" -borderStyle "in"; columnLayout; text " "; text "Enter the suffix of the group above the object:"; text "(Grp is default if you used the button above)"; text " "; textField -w 120 suffix; textField -edit -tx "Grp" suffix; text " "; setParent ..; setParent ..; frameLayout -label "Step 4: Choose Constraint Type" -labelAlign "bottom" -borderStyle "in"; columnLayout; text " "; text "Make sure a worldLoc exists,"; text "select local control, then controller"; text " "; // This is for the radio buttons radioCollection constraintType; radioButton -label "Point Constraint Setup" pointC; radioButton -label "Orient Constraint Setup" orientC; radioButton -label "Parent Constraint Setup" parentC; radioCollection -e -select parentC constraintType; text " "; setParent ..; setParent ..; frameLayout -label "Step 5: Select Local Control then Object" -labelAlign "bottom" -borderStyle "in"; columnLayout; text " "; button - w 280 -l "Create Connections" - h 50 -c doConstraint; setParent ..; setParent ..; window -e -wh 280 640 LWWindow; showWindow LWWindow; } // Inputs/Outputs: None // This procedure checks to make sure all objects exist (and not as duplicates), then sets up the constraints on the // given controllers assuming no errors. Also creates an atribute on controller and SDKs it. global proc doConstraint() { // Current selection - controller then joint string $sel[] = `ls -sl`; string $local = $sel[0]; string $obj = $sel[1]; // Get constraint type from UI string $constraintType = `radioCollection -query -select constraintType`; // New string for name of locator string $name = `substring $local 1 (size($local) - 7)`; string $suffix = `textField -q -text suffix`; string $object = $obj + $suffix; // Error checking variable int $error = 0; if ($suffix == "") { warning "Please enter a suffix for the group"; $error = 1; } // Checking to see if there are things selected if ($local == "" || $object == "") { // 2 objects were not found warning "Please select the local controller and then the object to be setup \n"; // Do not continue $error = 1; } // Check to see there is a worldLoc for the switch if (!`objExists worldLoc`) { warning "Make sure \"worldLoc\" exists"; $error = 1; } // If locator1 exists, warn or else script will fail if (`objExists locator1`) { warning "Rename or delete locator1 to continue"; $error = 1; } if (!`objExists $object`) { warning "Make sure you have a group above the object and the suffix is correct"; $error = 1; } // Continue if no object exists "locator1" if ($error == 0) { // Create local locator and rename according to local object, parent to local object CreateLocator; rename locator1 ($name + "Loc"); delete `pointConstraint $local ($name + "Loc")`; parent ($name + "Loc") $local; } // Continue if no errors exist if ($error == 0) { // New string for constraint type (SDKs) string $constraint = "random"; // Type of switch: orient, point or parent if ($constraintType == "pointC") { pointConstraint -mo -n ($object + "_pointConstraintLocalWorld")($name + "Loc") worldLoc $object; $constraint = "_pointConstraintLocalWorld."; } if ($constraintType == "orientC") { orientConstraint -mo -n ($object + "_orientConstraintLocalWorld")($name + "Loc") worldLoc $object; $constraint = "_orientConstraintLocalWorld."; } if ($constraintType == "parentC") { parentConstraint - mo -n ($object + "_parentConstraintLocalWorld")($name + "Loc") worldLoc $object; $constraint = "_parentConstraintLocalWorld."; } // Add attribute for switch on object to be setup addAttr -ln localWorld -k 1 -at "float" -min 0 -max 10 -dv 0 ($obj); // SDKs for the switch setAttr ($obj + ".localWorld") 0; setAttr ($object + $constraint + $name + "LocW0") 1; setAttr ($object + $constraint + "worldLocW1") 0; setDrivenKeyframe -cd ($obj + ".localWorld") ($object + $constraint + $name + "LocW0"); setDrivenKeyframe -cd ($obj + ".localWorld") ($object + $constraint + "worldLocW1"); setAttr ($obj + ".localWorld") 10; setAttr ($object + $constraint + $name + "LocW0") 0; setAttr ($object + $constraint + "worldLocW1") 1; setDrivenKeyframe -cd ($obj + ".localWorld") ($object + $constraint + $name + "LocW0"); setDrivenKeyframe -cd ($obj + ".localWorld") ($object + $constraint + "worldLocW1"); setAttr ($obj + ".localWorld") 10; // If all that went through, you win if ($error == 0) print "Local/World Switch Successfully Setup!"; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////// // This is simply another window to display the help document global proc LWHelp() { string $helpText = "Overview:\n\ndrLocalWorld will setup a local world system for a given \"object\" based on the \"local\" control selected. \n\nStep 1: Create a worldLoc using the button. You only need one of these in the scene. \n\nStep 2: Create a group padding with the same oriention and position of the object if there is not already. Press the button with the object selected to do this. \n\nStep 3: Insert the suffix for the group padding (Grp by default).\n\nStep 4: Choose your constraint type.\n\nStep 5: Select the local control then the object you want to have the constraint on it. \n\nStep 6: Press the create connections button"; if (`window -q -ex LWHelp`) deleteUI LWHelp; window -title "DRhodes' Local World" -resizeToFitChildren 1 -maximizeButton 0 -sizeable 1 -widthHeight 500 350 LWHelp; paneLayout; scrollField -ed 0 -wordWrap 1 -font plainLabelFont -w 360 -h 350 -numberOfLines 15 -text $helpText; window -e -wh 400 370 LWHelp; showWindow LWHelp; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// // This section groups an object to itself to have clean transforms global proc string group2Self() { string $selection[] = `ls -sl`; string $obj = $selection[0]; int $error = 0; string $grp; if ($obj == "") { warning "Make sure you select the object you want grouped"; $error = 1; } if ($error == 0) { $grp = `group -em -n ($obj + "Grp")`; delete `parentConstraint $obj $grp`; parent $obj $grp; //Freeze transforms of the object makeIdentity -apply 1 -t 1 -r 1 $obj; return $grp; } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////