/* Name: acAlignLocator.mel Author: Allen Curtis Date: Oct 2008 Description: Move locator/object pivot point. Instructions - Select joint. Shift-select locator or object. Click Match Pivot button. Move locator/object to joint's pivot position. Instructions - Select joint. Shift-select locator or object. Click the Align button. Create locator and automatically align with selected. Instructions - Select joint. Press Locator button. Additional buttons for creating nurbs box and arrow controllers. These are not automatically aligned. To align to a joint: select the joint, shift-select the nurbs object, and click the Align button. */ string $getCurrentSelected[]; float $positionNow[]; global proc acAlignLocator(){ if(`window -exists acAlignLocatorWindow`) deleteUI acAlignLocatorWindow; window -title "Locator/Align" acAlignLocatorWindow; columnLayout -columnOffset "left" 15 -rs 5 ColumnLayout; //Controls for viewing position of current selection. text -label "Selection" -m 1 SelectionLabel; text -label "x:" -align "left" labelX; text -label "y:" -align "left" labelY; text -label "z:" -align "left" labelZ; text -label "Pivot Position" -align "left" labelPointMessage; button -label "Pivot Position" -command "updatePosition" CurrentSelButton; button -label "MatchPivot" -command "acMatchPivotPt" MatchSelButton; button -label "Align" -command "acAlign" MoveButton; button -label "Locator-Aligned" -command "acLocator" LocatorButton; button -label "Box" -command "acControllerBox" BoxButton; button -label "Arrow" -command "acControllerArrow" ArrowButton; //These floatFieldGrp's are invisible. Their only purpose here is //to use their precision flag as a round-off function for text labels. //-m/manage flag used for invisibility. floatFieldGrp -v1 0.0 -precision 6 -m 0 RoundOffX; floatFieldGrp -v1 0.0 -precision 6 -m 0 RoundOffY; floatFieldGrp -v1 0.0 -precision 6 -m 0 RoundOffZ; window -edit -wh 200 350 acAlignLocatorWindow; showWindow acAlignLocatorWindow; } //Get pivot position of selected. global proc updatePosition(){ $getCurrentSelected =`ls -sl`; //Create position variables; $positionNow = `xform -q -ws -piv ($getCurrentSelected[0])`; floatFieldGrp -edit -v1 $positionNow[0] RoundOffX; string $posXNow=`floatFieldGrp -q -v1 RoundOffX`; floatFieldGrp -edit -v1 $positionNow[1] RoundOffY; string $posYNow=`floatFieldGrp -q -v1 RoundOffY`; floatFieldGrp -edit -v1 $positionNow[2] RoundOffZ; string $posZNow=`floatFieldGrp -q -v1 RoundOffZ`; text -edit -label $getCurrentSelected[0] SelectionLabel; text -edit -label ("x: " + $posXNow) labelX; text -edit -label ("y: " + $posYNow) labelY; text -edit -label ("z: " + $posZNow) labelZ; } //Move pivot of 2nd selection to match pivot of 1st selected. global proc acMatchPivotPt(){ $getCurrentSelected =`ls -sl -fl`; $positionNow = `xform -q -ws -piv ($getCurrentSelected[0])`; float $x= $positionNow[0]; float $y = $positionNow[1]; float $z = $positionNow[2]; string $alignxToPt[] =`xform -ws -piv $x $y $z ($getCurrentSelected[1])`; } //Move 2nd selected to align with 1st selected. global proc acAlign(){ $getCurrentSelected =`ls -sl -fl`; //Create position variables; $positionNow = `xform -q -ws -piv ($getCurrentSelected[0])`; //Move 2nd selection to position of 1st selection. string $pointConstrain[] = `pointConstraint -w 1 $getCurrentSelected[0] $getCurrentSelected[1]`; refresh; delete $pointConstrain; floatFieldGrp -edit -v1 $positionNow[0] RoundOffX; string $posXNow=`floatFieldGrp -q -v1 RoundOffX`; floatFieldGrp -edit -v1 $positionNow[1] RoundOffY; string $posYNow=`floatFieldGrp -q -v1 RoundOffY`; floatFieldGrp -edit -v1 $positionNow[2] RoundOffZ; string $posZNow=`floatFieldGrp -q -v1 RoundOffZ`; text -edit -label $getCurrentSelected[0] SelectionLabel; text -edit -label ("x: " + $posXNow) labelX; text -edit -label ("y: " + $posYNow) labelY; text -edit -label ("z: " + $posZNow) labelZ; } //Create locator automatically aligned with selected. global proc acLocator(){ $getCurrentSelected =`ls -sl -fl`; //Create locator and align with pivot of selected. $positionNow = `xform -q -ws -piv ($getCurrentSelected[0])`; //Move 2nd selection to position of 1st selection. string $locator[] = `spaceLocator -p $positionNow[0] $positionNow[1] $positionNow[2]`; $getCurrentSelected =`ls -sl -fl`; CenterPivot $getCurrentSelected[0]; scale 3 3 3 $getCurrentSelected[0];//Edit this scale to whatever works best. makeIdentity -apply true -t 1 -r 1 -s 0 -n 0 $getCurrentSelected[0]; } //Create a controller nurbs box. global proc acControllerBox(){ curve -d 1 -p -3 -3 3 -p 3 -3 3 -p 3 3 3 -p -3 3 3 -p -3 -3 3 -p -3 -3 -3 -p -3 3 -3 -p -3 3 3 -p 3 3 3 -p 3 3 -3 -p -3 3 -3 -p -3 -3 -3 -p 3 -3 -3 -p 3 3 -3 -p 3 3 3 -p 3 -3 3 -p 3 -3 -3 -p 3 3 -3; xform -cp; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; } //Create a controller nurbs arrow. global proc acControllerArrow(){ curve -d 1 -p 0 0 6 -p -7.2 0 0 -p -3.6 0 0 -p -3.6 0 -12 -p 3.6 0 -12 -p 3.6 0 0 -p 7.2 0 0 -p 0 0 6 -k 0 -k 9.3723 -k 12.9723 -k 24.9723 -k 32.1723 -k 44.1723 -k 47.7723 -k 57.144599; xform -cp; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; }