//******************************************************************************************** //******************************************************************************************** //*** *** //*** ALIGN VERTICES v2.0 © Xavier GOUCHET 2005 *** //*** *** //*** *** //******************************************************************************************** //******************************************************************************************** // // // DESCRIPTION: // it takes all the selected vertices and align them on a plane // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // // AUTHOR : // Xavier Gouchet , 2005 // http://xgouchet.fr/ // xavier.gouchet@gmail.com // // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // // INSTALLATION: // // place the "alignVertices.mel" script in your script directory // defaults : // OSX : ~/Library/Preferences/AliasWavefront/maya/scripts/ // Windows : My Documents/maya/scripts/ // // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // // USAGE: // Select the vertices you want to align and run the following command // alignVertices(); // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // // v2.0 (January 18, 2006) // - // - Fixed "max align" bugs. // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // // Please report bugs, suggestions, comments or others at // gouchet.xavier@free.fr // // procedure alignX (all vertices are aligned on the YZ plane) global proc alignX(float $newX, int $type, int $keepsel){ // the $type parametre tells "where" we align the vertices // if set to 1, the X value will be $newX (wich should be 0, by default) // if set to 2, the X value of all vertices will be the min value // if set to 3, the X value of all vertices will be the max value // if set to 4 the X value will be an average of all X value // first : get the selection of vertices $sel = `ls -fl -sl`; string $s; //Then if we use the average value, we calculate this value float $posX, $posY, $posZ; if ($type == 1){ $posX = $newX; } if ($type == 2) {//to calculate the min X value float $min; $s = $sel[0]; $x = `xform -q -ws -t $s`; $min = $x[0]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[0]<$min){$min = $x[0];} clear $x; } $posX = $min; } if ($type == 3) { // to calculate the max X value float $max; $s = $sel[0]; $x = `xform -q -ws -t $s`; $max = $x[0]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[0]>$max){$max = $x[0];} clear $x; } $posX = $max; } if ($type == 4) { // to calculate the average X value float $max, $min; $s = $sel[0]; $x = `xform -q -ws -t $s`; $min = $x[0]; $max = $x[0]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[0]>$max){$max = $x[0];} if ($x[0]<$min){$min = $x[0];} clear $x; } $posX = ($max+$min)/2; } for ($s in $sel){ select -r $s; $x = `xform -q -ws -t $s`; $posY = $x[1]; $posZ = $x[2]; xform -ws -t $posX $posY $posZ $s; clear $x; } select -cl; if ($keepsel==1){ select -r $sel; } } // end of proc alignX // procedure alignY (all vertices are aligned on the XZ plane) global proc alignY(float $newY, int $type, int $keepsel){ // the $type parametre tells "where" we align the vertices // if set to 1, the Y value will be $newX (wich should be 0, by default) // if set to 2, the Y value of all vertices will be the min value // if set to 3, the Y value of all vertices will be the max value // if set to 4 the Y value will be an average of all Y value // first : get the selection of vertices $sel = `ls -fl -sl`; string $s; //Then if we use the average value, we calculate this value float $posX, $posY, $posZ; if ($type == 1){ $posY = $newY; } if ($type == 2) {//to calculate the min Y value float $min; $s = $sel[0]; $x = `xform -q -ws -t $s`; $min = $x[1]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[1]<$min){$min = $x[1];} clear $x; } $posY = $min; } if ($type == 3) { // to calculate the max Y value float $max; $s = $sel[0]; $x = `xform -q -ws -t $s`; $max = $x[1]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[1]>$max){$max = $x[1];} clear $x; } $posY = $max; } if ($type == 4) { // to calculate the average Y value float $max, $min; $s = $sel[0]; $x = `xform -q -ws -t $s`; $min = $x[1]; $max = $x[1]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[1]>$max){$max = $x[1];} if ($x[1]<$min){$min = $x[1];} clear $x; } $posY = ($max+$min)/2; } for ($s in $sel){ select -r $s; $x = `xform -q -ws -t $s`; $posX = $x[0]; $posZ = $x[2]; xform -ws -t $posX $posY $posZ $s; clear $x; } select -cl; if ($keepsel==1){ select -r $sel; } } // end of proc alignY // procedure alignZ (all vertices are aligned on the XY plane) global proc alignZ(float $newZ, int $type, int $keepsel){ // the $type parametre tells "where" we align the vertices // if set to 1, the Z value will be $newX (wich should be 0, by default) // if set to 2, the Z value of all vertices will be the min value // if set to 3, the Z value of all vertices will be the max value // if set to 4 the Z value will be an average of all Z value // first : get the selection of vertices $sel = `ls -fl -sl`; string $s; //Then if we use the average value, we calculate this value float $posX, $posY, $posZ; if ($type == 1){ $posZ = $newZ; } if ($type == 2) {//to calculate the min Z value float $min; $s = $sel[0]; $x = `xform -q -ws -t $s`; $min = $x[2]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[2]<$min){$min = $x[2];} clear $x; } $posZ = $min; } if ($type == 3) { // to calculate the max Z value float $max; $s = $sel[0]; $x = `xform -q -ws -t $s`; $max = $x[2]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[2]>$max){$max = $x[2];} clear $x; } $posZ = $max; } if ($type == 4) { // to calculate the average Z value float $max, $min; $s = $sel[0]; $x = `xform -q -ws -t $s`; $min = $x[2]; $max = $x[2]; clear $x; for ($s in $sel){ $x = `xform -q -ws -t $s`; if ($x[2]>$max){$max = $x[2];} if ($x[2]<$min){$min = $x[2];} clear $x; } $posZ = ($max+$min)/2; } for ($s in $sel){ select -r $s; $x = `xform -q -ws -t $s`; $posX = $x[0]; $posY = $x[1]; xform -ws -t $posX $posY $posZ $s; clear $x; } select -cl; if ($keepsel==1){ select -r $sel; } } // end of proc alignZ // procedure doAlignVertices : get values from the window and align the selected vertices. global proc doAlignVertices(){ int $type; int $axis; float $constant; int $keepSel; if (`control -exists avAxis`) { $axis = (`radioButtonGrp -q -sl avAxis`); } if (`control -exists keepSel`) { $keepSel = (`checkBox -q -v keepSel`); } if (`control -exists avType`) { $type = (`radioButtonGrp -q -sl avType`); } if (`control -exists avConstant`) { $constant = (`floatSliderGrp -q -v avConstant`); } if ($axis == 1) {alignX $constant $type $keepSel;}; if ($axis == 2) {alignY $constant $type $keepSel;}; if ($axis == 3) {alignZ $constant $type $keepSel;}; } // end of proc doAlignVertices // procedure alignWindow : creates the control window global proc alignWindow(){ // first if a window already exists we delete it if ((`window -ex alignVertices`) == true) deleteUI -window alignVertices; // we create te window window -title "AlignVertices v1.0" // name -rtf true // resize to fit children -s false -w 390 // width -h 200 alignVertices; $col = `columnLayout -cat "both" 10 -adj true -cal "left"`; separator -style "none" -h 10; // the axis selection radioButtonGrp -nrb 3 // number of radio btns -label "Axis : " // label of the group -la3 "X" "Y" "Z" // label of all 3 btns -cw4 80 40 40 40 // width of each column -cl4 "right" "left" "left" "left" -select 1 avAxis; separator -style "none" -h 10; // the type selection radioButtonGrp -nrb 4 // number of radio btns -label "Type : " // label of the group -la4 "constant" "min" "max" "average" // label of all 4 btns -cw5 80 70 70 70 70 // width of each column -cl5 "right" "left" "left" "left" "left" -on1 "floatSliderGrp -e -en true avConstant" -on2 "floatSliderGrp -e -en false avConstant" -on3 "floatSliderGrp -e -en false avConstant" -on4 "floatSliderGrp -e -en false avConstant" -select 1 avType; separator -style "in" -w 400 -h 10; // the constant value setting floatSliderGrp -label "Constant Value:" -columnAlign3 "right" "left" "left" -columnWidth3 100 50 200 -min -10.0 -max 10.0 // min and max values -fmn -1000.0 -fmx 1000.0 // boundaries to the field value -value 0 -field true avConstant; separator -style "none" -h 10; checkBox -label "Keep Selection" -v 1 -w 250 keepSel; // create the Butns "Apply&close" "Apply" and "Close" separator -style "none" -height 15; rowLayout -numberOfColumns 3 -columnAttach3 "both" "both" "both" -columnAlign3 "center" "center" "center" buttons; button -label "Apply and Close" -command "doAlignVertices(); deleteUI -window alignVertices" ; button -label "Apply" -command "doAlignVertices();" ; button -label "Close Window" -command "deleteUI -window alignVertices" ; setParent ..; separator -style "none" -h 10; setParent ..; showWindow alignVertices; } // end of proc alignWindow // the main procedure global proc alignVertices(){ alignWindow; }