//Name: acUVMoveShell.mel //Author: Allen Curtis //Date: June 2009 //PURPOSE: TO MOVE UV SHELLS IN THE TEXTURE EDITOR WINDOW //BY ALIGNING RIGHT,LEFT, TOP, OR BOTTOM TO ABSOLUTE POSITION. string $getCurrentSelected[]; float $positionNow[]; global proc acUVMoveShell(){ if(`window -exists acUVMoveShellWindow`) deleteUI acUVMoveShellWindow; window -title "Move UV Shell" -widthHeight 235 476 acUVMoveShellWindow; columnLayout -columnOffset "left" 15 -rs 5 ColumnLayout; //Controls for viewing position of current selection. text -label "Selection" -m 1 SelectionLabel; text -label "u:" -align "left" labelX; text -label "v:" -align "left" labelY; text -label "Point Position" -align "left" labelPointMessage; button -label "Point Position" -command "updateUVSelection" CurrentSelButton; button -label "Select UV Shell" -command "getUVShell" AlignButton; text -label "_________________________________" -align "left";//hack for spacing checkBox -label "U axis" -value 1 checkX; checkBox -label "V axis" checkY; radioButtonGrp -numberOfRadioButtons 2 -columnAlign 1 "left" -columnWidth 1 60 -columnWidth 2 80 -label "Position:" -labelArray2 "Max" "Min" -sl 2 radioCoordinates; //Layout inside another layout. formLayout -nd 100 xyzLayout; button -label "u" -width 20 -c "inputX" xButton; button -label "v" -width 20 -c "inputY" yButton; text -label "- From Selected" fromSelected; columnLayout -parent ColumnLayout textLayout; //For user input. textField -width 80 PositionField; columnLayout -parent ColumnLayout buttonLayout; button -label "Move" -width 80 -command "moveUV" MoveXButton; //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 RoundOffU; floatFieldGrp -v1 0.0 -precision 6 -m 0 RoundOffV; floatFieldGrp -v1 0.0 -precision 6 -m 0 RoundOffZ; formLayout -edit -attachForm xButton "top" 5 -attachForm xButton "left" 5 -attachForm yButton "top" 5 -attachControl yButton "left" 10 xButton -attachForm fromSelected "top" 5 -attachControl fromSelected "left" 5 yButton xyzLayout; window -edit -widthHeight 235 400 acUVMoveShellWindow; showWindow acUVMoveShellWindow; } //Selects UV shell and displays bounding box info. global proc getUVShell(){ SelectUVShell; float $uvMin[2]; float $uvMax[2]; //Get bounding box info. float $uvBox[] = `polyEvaluate -bc2`; $uvMin[0] = $uvBox[0]; $uvMin[1] = $uvBox[2]; $uvMax[0] = $uvBox[1]; $uvMax[1] = $uvBox[3]; //Display bounding box info. print("uMin:"+$uvMin[0]+" uMax:"+$uvMax[0]+" vMin:"+$uvMin[1]+" vMax:"+$uvMax[1]+"\n"); } global proc inputX(){ string $inputSel[]; float $x; string $xvalue = `text -q -label labelX`; //Tokenize separates the string into an array. string $token = `tokenize $xvalue ":" $inputSel`; $x = $inputSel[1]; textField -edit -tx $x PositionField; } global proc inputY(){ string $inputSel[]; float $x; string $xvalue = `text -q -label labelY`; //Tokenize separates the string into an array. string $token = `tokenize $xvalue ":" $inputSel`; $x = $inputSel[1]; textField -edit -tx $x PositionField; } //Move position based on textfield's user input. global proc moveUV(){ string $getText = `textField -q -tx PositionField`; float $x = $getText; float $uvMin[2]; float $uvMax[2]; int $coordinates = `radioButtonGrp -q -sl radioCoordinates`; int $checkValX=`checkBox -query -value checkX`; //Align Max U value. if(($checkValX==1)&&($coordinates==1)){ //Get uv shell's bounding box. float $uvBox[] = `polyEvaluate -bc2`; $uvMin[0] = $uvBox[0]; $uvMin[1] = $uvBox[2]; $uvMax[0] = $uvBox[1]; $uvMax[1] = $uvBox[3]; //getText from textfield. float $absolutePosition = $x; if ($absolutePosition > $uvMax[0]){ //inner if else float $move = $absolutePosition - $uvMax[0]; string $cmd = `polyEditUV -r true -u $move`; } else if ($absolutePosition < $uvMax[0]){ float $move = $uvMax[0] - $absolutePosition; $move = $move * (-1); string $cmd = `polyEditUV -r true -u $move`; }//end inner if else //Align Min U value. }else if(($checkValX==1)&&($coordinates==2)){ //Get uv shell's bounding box. float $uvBox[] = `polyEvaluate -bc2`; $uvMin[0] = $uvBox[0]; $uvMin[1] = $uvBox[2]; $uvMax[0] = $uvBox[1]; $uvMax[1] = $uvBox[3]; //getText from textfield. float $absolutePosition = $x; if ($absolutePosition > $uvMin[0]){ //inner if else float $move = $absolutePosition - $uvMin[0]; string $cmd = `polyEditUV -r true -u $move`; } else if ($absolutePosition < $uvMin[0]){ float $move = $uvMin[0] - $absolutePosition; $move = $move * (-1); string $cmd = `polyEditUV -r true -u $move`; }//end inner if else } //Align Max V value. int $checkValY=`checkBox -query -value checkY`; if(($checkValY==1)&&($coordinates==1)){ //Get uv shell's bounding box. float $uvBox[] = `polyEvaluate -bc2`; $uvMin[0] = $uvBox[0]; $uvMin[1] = $uvBox[2]; $uvMax[0] = $uvBox[1]; $uvMax[1] = $uvBox[3]; //getText from textfield. float $absolutePosition = $x; if ($absolutePosition > $uvMax[1]){ //inner if else float $move = $absolutePosition - $uvMax[1]; string $cmd = `polyEditUV -r true -v $move`; } else if ($absolutePosition < $uvMax[1]){ float $move = $uvMax[1] - $absolutePosition; $move = $move * (-1); string $cmd = `polyEditUV -r true -v $move`; }//end inner if else //Align Min V value. }else if(($checkValY==1)&&($coordinates==2)){ //Get uv shell's bounding box. float $uvBox[] = `polyEvaluate -bc2`; $uvMin[0] = $uvBox[0]; $uvMin[1] = $uvBox[2]; $uvMax[0] = $uvBox[1]; $uvMax[1] = $uvBox[3]; //getText from textfield. float $absolutePosition = $x; if ($absolutePosition > $uvMin[1]){ //inner if else float $move = $absolutePosition - $uvMin[1]; string $cmd = `polyEditUV -r true -v $move`; } else if ($absolutePosition < $uvMin[1]){ float $move = $uvMin[1] - $absolutePosition; $move = $move * (-1); string $cmd = `polyEditUV -r true -v $move`; }//end inner if else } } //Show current selection and position. If more than one vertex is selected, //only the first in the selection list is shown. global proc updateUVSelection(){ $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 51 -sm 73`)>0){ //Create position variables; $positionNow = `polyEditUV -query $getCurrentSelected[0]`; floatFieldGrp -edit -v1 $positionNow[0] RoundOffU; string $posXNow=`floatFieldGrp -q -v1 RoundOffU`; floatFieldGrp -edit -v1 $positionNow[1] RoundOffV; string $posYNow=`floatFieldGrp -q -v1 RoundOffV`; text -edit -label $getCurrentSelected[0] SelectionLabel; text -edit -label ("u: " + $posXNow) labelX; text -edit -label ("v: " + $posYNow) labelY; //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 43 -sm 44 -sm 45 -sm 48 -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 ("u:") labelX; text -edit -label ("v:") labelY; floatFieldGrp -edit -l "N/A" RoundOffU; }else if(size(`filterExpand -sm 12 -sm 68`)>0){ $positionNow = `objectCenter($getCurrentSelected[0])`; text -edit -label $getCurrentSelected[0] SelectionLabel; floatFieldGrp -edit -v1 $positionNow[0] RoundOffU; string $posXNow=`floatFieldGrp -q -v1 RoundOffU`; floatFieldGrp -edit -v1 $positionNow[1] RoundOffV; string $posYNow=`floatFieldGrp -q -v1 RoundOffV`; text -edit -label ("u:" + $posXNow) labelX; text -edit -label ("v:" + $posYNow) labelY; } }