// randomizer.mel // by Naughty (naughty_genepool@hotmail.com) // // Randomizer is a basic UI tool that allows you to easily randomize the position, // rotation and scale of any selected objects (at the object level). Great for jumbling // up arrays of objects like trees & rocks or items on a desktop etc.. // // Extra options allow you to randomize about World Space (instead of around the objects // local axis), lock the XYZ scales of objects and avoid negative scales (so objects don't // flip inside-out). Not much more to say, does exactly what it says on the tin. // // Usage: // // randomizer; // opens the randomizer UI // // // goto: // http://www.naughtynathan.supanet.com/mel.htm // for more detailed explanations, pictures and even more MEL scripts... global proc doRandomize() { float $tXYZ[4] = `floatFieldGrp -q -v transXYZ`; float $rXYZ[4] = `floatFieldGrp -q -v rotateXYZ`; float $sXYZ[4] = `floatFieldGrp -q -v scaleXYZ`; int $worldAxe = `checkBox -q -v worldAxis`; int $uniform = `checkBox -q -v uniScale`; int $avoid = `checkBox -q -v avoid`; float $translateX = $tXYZ[0]; float $translateY = $tXYZ[1]; float $translateZ = $tXYZ[2]; float $rotateX = $rXYZ[0]; float $rotateY = $rXYZ[1]; float $rotateZ = $rXYZ[2]; float $scaleX = $sXYZ[0]; float $scaleY = $sXYZ[1]; float $scaleZ = $sXYZ[2]; string $usedPanel = `getPanel -wf`; // allows instant, frustration free Undo-ing! float $existingScale[3]; float $rndX; float $rndY; float $rndZ; string $selObjects[] = `ls -sl -l -tr`; for ($obj in $selObjects) { if ($worldAxe) { // move in world space move -r -xyz `rand (-$translateX) $translateX` `rand (-$translateY) $translateY` `rand (-$translateZ) $translateZ` $obj; rotate -r `rand (-$rotateX) $rotateX` `rand (-$rotateY) $rotateY` `rand (-$rotateZ) $rotateZ` $obj; } else { // move in object space move -r -os -xyz `rand (-$translateX) $translateX` `rand (-$translateY) $translateY` `rand (-$translateZ) $translateZ` $obj; rotate -r -os `rand (-$rotateX) $rotateX` `rand (-$rotateY) $rotateY` `rand (-$rotateZ) $rotateZ` $obj; } $existingScale = `getAttr ($obj+".scale")`; $rndX = `rand (-$scaleX) $scaleX`; $rndY = `rand (-$scaleY) $scaleY`; $rndZ = `rand (-$scaleZ) $scaleZ`; if ($uniform) $rndY = $rndZ = $rndX; scale -a ($existingScale[0] + $rndX) ($existingScale[1] + $rndY) ($existingScale[2] + $rndZ) $obj; if ($avoid) { $existingScale = `getAttr ($obj+".scale")`; if ($existingScale[0] < 0) setAttr ($obj+".scaleX") (0-$existingScale[0]); if ($existingScale[1] < 0) setAttr ($obj+".scaleY") (0-$existingScale[1]); if ($existingScale[2] < 0) setAttr ($obj+".scaleZ") (0-$existingScale[2]); } } setFocus $usedPanel ; // allows instant, frustration free Undo-ing! } global proc randomizer() { string $usedPanel = `getPanel -wf`; if ( `window -exists randomizerUI` ) { deleteUI -window randomizerUI; // windowPref -remove randomizerUI; // kill prefs } window -title "Randomizer v1.0" -wh 206 175 -s 0 randomizerUI; columnLayout -adj 1 -co "both" 4 UIParent; separator -st "none" -h 4; floatFieldGrp -cw4 55 45 45 45 -l "Translate" -nf 3 -pre 0 -v 0 0 0 0 -ann "Translation Modifiers X/Y/Z. Move objects by random +/- this amount." transXYZ ; floatFieldGrp -cw4 55 45 45 45 -l "Rotate" -nf 3 -pre 0 -v 0 0 0 0 -ann "Rotation Modifiers X/Y/Z. Rotate objects by random +/- this amount." rotateXYZ ; floatFieldGrp -cw4 55 45 45 45 -l "Scale" -nf 3 -pre 0 -v 0 0 0 0 -ann "Scale SHIFT modifiers X/Y/Z. Scale objects by random +/- this amount." scaleXYZ ; separator -st "none" -h 2; columnLayout -co "left" 56 ; checkBox -l "World Space" -al "left" -v 0 -ann "Translates objects in world space instead of along their Local axes (default)." worldAxis ; checkBox -l "Uniform Scale" -al "left" -v 0 -onc "floatFieldGrp -e -en2 0 scaleXYZ; floatFieldGrp -e -en3 0 scaleXYZ" -ofc "floatFieldGrp -e -en2 1 scaleXYZ; floatFieldGrp -e -en3 1 scaleXYZ" -ann "Scale objects uniformly, instead of different random values for each axis." uniScale ; checkBox -l "Avoid Negative Scales" -al "left" -v 0 -ann "Changes any resulting negative scale values into positive ones. Prevents objects 'mirroring'." avoid ; setParent ..; separator -st "none" -h 2; formLayout -nd 100 buttons; button -l "Clear" -c "floatFieldGrp -e -v 0 0 0 0 transXYZ; floatFieldGrp -e -v 0 0 0 0 rotateXYZ; floatFieldGrp -e -v 0 0 0 0 scaleXYZ" -ann "Reset all input fields to 0." resetButton; button -l "Randomize!" -c "doRandomize" -ann "DO IT YOU SLAG!" goButton; formLayout -e -af resetButton top 0 -af goButton top 0 -af resetButton bottom 0 -af goButton bottom 0 -af resetButton left 0 -af goButton right 0 -ap resetButton right 2 28 -ap goButton left 2 28 buttons; setParent ..; showWindow; setFocus $usedPanel ; }