////////////////////////////////////////////////////////////////////////////////////////////// // // drAlignControl: // // This script will align a control to a joint and connect // the joint to the control. This is quite useful for FK systems when // you need the orientation of the control to match the orientation // of the joint, or you can offset. This can be used to snap to // another object as well, or merely grouping to self to avoid garbage // values. // // Author: David Rhodes // Contact: digitalsandwichinc@hotmail.com // ////////////////////////////////////////////////////////////////////////////////////////////// // This serves as the UI for both scripts, rename and align // Input/Output: None global proc drAlignControl () { if (`window -q -ex alignWindow`) deleteUI alignWindow; window -t "DRhodes Magic Align" alignWindow; string $form = `formLayout`; string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5`; formLayout -edit -attachForm $tabs "top" 0 -attachForm $tabs "left" 0 -attachForm $tabs "bottom" 0 -attachForm $tabs "right" 0 $form; string $align = `rowColumnLayout -nr 15`; // This is for the radio buttons text "Select the controller, then the joint."; radioCollection alignType; radioButton -label "Align Orientation" a; radioButton -label "Offset Orientation" o; radioCollection -e -select a alignType; // Check boxes checkBox -l "Attach Control" -value 1 attatchBox; checkBox -l "Snap to Object" -value 1 snapBox; button -w 50 -l "Align" -c doAlign; text " "; text "Select the curve's CVs to rotate in increments of 45."; // Check boxes rowColumnLayout -nc 3; radioCollection rotateType; radioButton -label "X" x; radioButton -label "Y" y; radioButton -label "Z" z; radioCollection -e -select x rotateType; setParent..; button -w 50 -l "Rotate" -c "rotateCV"; setParent ..; string $name = `rowColumnLayout -nr 6`; text -l "Press Enter on keypad to rename."; textField newName; text " "; button -l "Next Joint" -c "pickWalk -d down"; button -l "Previous Joint" -c "pickWalk -d up"; textField -edit -enterCommand ("renameJoint") newName; setParent ..; tabLayout -edit -tabLabel $align "Align Control" -tabLabel $name "Rename Joints" $tabs; window -e -wh 295 320 alignWindow; showWindow alignWindow; } // This procedure will align a control to a joint and connect the joint to the control based on user input // Inputs/Outputs: None global proc doAlign () { // Current selection - controller then joint string $sel[] = `ls -sl`; string $controller = $sel[0]; string $joint = $sel[1]; // Error checking variable int $error = 0; int $snap = `checkBox -query -value snapBox`; int $connect = `checkBox -query -value attatchBox`; string $offset = `radioCollection -query -select alignType`; // Checking to see if there are things selected if ($controller == "" || $joint == "") { // 2 objects were not found warning "Please select the controller and then the joint \n"; // Do not continue $error = 1; } // If no errors, continue if ($error == 0) { select $controller; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; // Trash value group group -em -n ($controller + "Grp"); // Align null group and controller together, parent delete `orientConstraint $controller ($controller + "Grp")`; delete `pointConstraint $controller ($controller + "Grp")`; parent $controller ($controller + "Grp"); // Align everything to the joint (orient, point), if checked if ($snap == 1) delete `pointConstraint $joint ($controller + "Grp")`; // Align or offset based on radio button selection if ($offset == "a") delete `orientConstraint $joint ($controller + "Grp")`; // Connect controller to joint, if checked if ($connect == 1) orientConstraint -mo $controller $joint; print "Control Successfully Connected!"; } } // Rotates the CVs to align the curve to the orientation, for circles and such // No inputs, except it requires a selection. global proc rotateCV () { // Check user input radio buttons string $rot = `radioCollection -query -select rotateType`; if ($rot == "x") rotate -r 45 0 0; if ($rot == "y") rotate -r 0 45 0; if ($rot == "z") rotate -r 0 0 45; } //////////////////////////////////////////////////////////////////////////////////////////////////// // // drRenameJoint: // // This procedure will allow the user to quickly rename hierarchies without // clicking the name every single time. // // To use: Simply select the root or parent and rename using the text // field. Hit enter on the num pad to rename and move to the next child. // // Author: David Rhodes // Contact: digitalsandwichinc@hotmail.com // //////////////////////////////////////////////////////////////////////////////////////////////////// global proc renameJoint () { string $currentObjectName[] = `ls -sl`; string $newObjectName = `textField -q -text newName`; if (`size $currentObjectName` == 0) { warning "There is no selected object to rename."; return; } else { if (`size $newObjectName` == 0) { warning "There is no valid name to input."; return; } else { rename $currentObjectName $newObjectName; print "Object has been renamed.\n"; pickWalk -d down; setFocus newName; } } }