/* Name: acPivotComponents.mel Author: Allen Curtis Date: January 2008 Description: Moves pivot point of hilited object to last selected vertex position. The object and selected components of the object will have the new rotation and scale pivot. IMPORTANT: IN TOOL SETTINGS>ROTATE SETTINGS AND SCALE SETTINGS, ENABLE THE "COMPONENT USE OBJECT PIVOT" CHECKBOX. THIS SCRIPT ONLY WORKS WHEN THIS IS ENABLED. Could probably add "manipRotateContext -e -useObjectPivot true Rotate;" to this script in the acMovePivotPts function, but decided it might be safer to keep the option separate from the script. Having a tool setting change buried within a script may cause problems later, with settings being changed and the user not being aware of what caused the change. Would rather change it explicitly in the Tool Settings so that the user is aware of it and can edit the settings if needed. Instructions: 1.Select vertex of an object. 2.Press the Point Position button. Shows xyz position. 3.Press the Move Pivot button. Pivot moves to new position. 4. Select a group of vertices, edges, or faces and rotate or scale from the new pivot point. */ string $getCurrentSelected[]; float $positionNow[]; global proc acPivotComponents(){ if(`window -exists acPivotComponentsWindow`) deleteUI acPivotComponentsWindow; window -title "Move Pivot" acPivotComponentsWindow; 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 "Point Position" -align "left" labelPointMessage; button -label "Point Position" -command "updateSelection" CurrentSelButton; button -label "Move Pivot" -command "acMovePivotPts" MovePivotButton; //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 250 acPivotComponentsWindow; showWindow acPivotComponentsWindow; } //Moves pivot point to same position as last Point Position setting. global proc acMovePivotPts(){ string $alignxToPt[]; string $alignyToPt[]; string $alignzToPt[]; float $x; float $y; float $z; string $xvalue = `text -q -label labelX`; //Tokenize separates the string into an array. string $tokenX = `tokenize $xvalue ":" $alignxToPt`; //Could have made an extra float variable here, but string automatically casts (converts) to //a float value. $x = $alignxToPt[1]; string $yvalue = `text -q -label labelY`; string $tokenY = `tokenize $yvalue ":" $alignyToPt`; $y = $alignyToPt[1]; string $zvalue = `text -q -label labelZ`; string $tokenZ = `tokenize $zvalue ":" $alignzToPt`; $z = $alignzToPt[1]; float $pos[3] = `xform -ws -rp $x $y $z`; //Move Pivots of hilited object. string $sel[] =`ls -hl`; //Lists hilited objects/components. for ($current in $sel) { string $rp = $current + ".rotatePivot"; string $sp = $current + ".scalePivot"; move -a $x $y $z $sp $rp; }; } global proc updateSelection(){ $getCurrentSelected =`ls -sl`; //Filter selected through selection masks (-sm). if(size(`filterExpand -sm 22 -sm 23 -sm 24 -sm 28 -sm 30 -sm 31 -sm 35 -sm 36 -sm 39 -sm 40 -sm 41 -sm 42 -sm 46 -sm 47 -sm 49 -sm 50 -sm 73`)>0){ //Create position variables; $positionNow = `pointPosition($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; //Can move some of these selection masks to next statement below //for object center to display if needed. }else if(size(`filterExpand -sm 0 -sm 1 -sm 2 -sm 3 -sm 4 -sm 5 -sm 6 -sm 7 -sm 8 -sm 9 -sm 10 -sm 11 -sm 13 -sm 14 -sm 15 -sm 16 -sm 17 -sm 18 -sm 19 -sm 20 -sm 21 -sm 25 -sm 26 -sm 27 -sm 29 -sm 32 -sm 33 -sm 34 -sm 37 -sm 38 -sm 41 -sm 42 -sm 43 -sm 44 -sm 45 -sm 48 -sm 51 -sm 52 -sm 53 -sm 54 -sm 55 -sm 56 -sm 57 -sm 67 -sm 69 -sm 70 -sm 71 -sm 72`)>0){ text -edit -label $getCurrentSelected[0] SelectionLabel; text -edit -label ("x:") labelX; text -edit -label ("y:") labelY; text -edit -label ("z:") labelZ; floatFieldGrp -edit -l "N/A" RoundOffX; }else if(size(`filterExpand -sm 12 -sm 68`)>0){ $positionNow = `objectCenter($getCurrentSelected[0])`; text -edit -label $getCurrentSelected[0] SelectionLabel; 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 ("x:" + $posXNow) labelX; text -edit -label ("y:" + $posYNow) labelY; text -edit -label ("z:" + $posZNow) labelZ; } }