// Creation Date: Feb 2 2002 // Last Updated: Feb 2 2002 // Revision: 1.0 // Tested on Maya: 4.0 // // Name: averagePosition 1.0 // Author: Gino Dammers - gdammers@xs4all.nl // // Description: Remember those moments when you use the Scale manipulator to align a // couple of vertexes with eachother? You have to scale over and over again till // the scale manipulator locks (or flips out :)) ? Well this script does it for you.. // Select the vertexes and tell it which axis it should align the vertexes to.. // No more scalling till the manipulator locks. Little time saver when modeling. // // Installation: Place the script in your script directory // type averagePosition in the script editor and drag it to your shelf. // // Dedicated to: All the lazy modelers out there ;) // Or the ones that just wanna speed things up and get to the art part :) // // Disclaimer: Use at your own risk global proc performAveragePosition (string $axis) { string $selection[] = `ls -sl -flatten`; int $sizeSel = `size($selection)`; float $axisPosition[]; int $axisValue; float $sum; if ($axis == "-x") $axisValue = 0; if ($axis == "-y") $axisValue = 1; if ($axis == "-z") $axisValue = 2; for ($count = 0; $count < $sizeSel; $count ++) { float $vertexPosition[] = `pointPosition -w $selection[$count]`; $axisPosition[$count] = $vertexPosition[$axisValue]; } int $sizeAxisPosition = `size($axisPosition)`; for ($count = 0; $count < $sizeAxisPosition; $count ++) $sum = $sum + $axisPosition[$count]; // Average it out float $average = $sum / $sizeAxisPosition; // For some reason Maya sometimes gives me WAY huge numbers when calculating the positions // numbers like 51359337199294618000000000000000000000000000000000000000000 // If maya moves vertexes to these large positions coords there is NO WAY to Undo the command to get them // back to their original position and you can't move them back manually either.. Very weird. // Possible a bug in Maya.. Restarting Maya helps in most cases.. // // So here's where the HUGE numbers safeguard comes in. if ($average < 100000000.0) { // Move the vertexes to the new position. move -a $axis $average; } else { warning ("New calculated vertex position to great..[ " + $average + " ].. Restart Maya "); } } global proc averagePosition() { if (`window -exists AveragePosition`) deleteUI AveragePosition; window -width 200 -height 123 -sizeable false -t "Tool Settings" AveragePosition; string $form =`formLayout`; string $tabs = `tabLayout -innerMarginWidth 1 -innerMarginHeight 1`; frameLayout -label "Manipulation" -collapsable 1 -borderStyle "etchedIn" AveragePositionFrameLayout; formLayout AveragePositionForm; string $buttonX = `button -w 55 -label " X " -command "performAveragePosition ( \"-x\" )"`; string $buttonY = `button -w 55 -label " Y " -command "performAveragePosition ( \"-y\" )"`; string $buttonZ = `button -label " Z " -command "performAveragePosition ( \"-z\" )"`; string $buttonUndo = `button -label "Undo" -command "undo"`; setParent ..; setParent ..; setParent ..; tabLayout -edit -tabLabel AveragePositionFrameLayout "averagePosition 1.0" $tabs; formLayout -edit -attachForm $tabs "top" 2 -attachForm $tabs "left" 2 -attachForm $tabs "bottom" 2 -attachForm $tabs "right" 2 $form; formLayout -edit -attachForm $buttonX "top" 3 -attachForm $buttonX "left" 3 -attachOppositeControl $buttonY "top" 0 $buttonX -attachControl $buttonY "left" 2 $buttonX -attachOppositeControl $buttonZ "top" 0 $buttonY -attachControl $buttonZ "left" 2 $buttonY -attachForm $buttonZ "right" 3 -attachControl $buttonUndo "top" 0 $buttonY -attachOppositeControl $buttonUndo "left" 0 $buttonX -attachOppositeControl $buttonUndo "right" 0 $buttonZ -attachNone $buttonUndo "bottom" AveragePositionForm; showWindow; }