//mdTater.mel by Max Dayan //Tater randomly transforms the selected objects based on user selections // // //This is the doIT portion... //Rotation Proc global proc ranRot(float $minVal, float $maxVal){ //Makes $minVal a negative number //$minVal = $minVal*-1; //Selects the objects string $sel[] = `ls -sl`; //create variables from check box group values string $grp2X = (`checkBoxGrp -q -value1 myChkBxGrp2`); string $grp2Y = (`checkBoxGrp -q -value2 myChkBxGrp2`); string $grp2Z = (`checkBoxGrp -q -value3 myChkBxGrp2`); //For loop to rotate each object in the selection for ($each in $sel){ float $rotx = rand ($minVal, $maxVal); float $roty = rand ($minVal, $maxVal); float $rotz = rand ($minVal, $maxVal); //If the check box is ON rotate that axis if ($grp2X ==1) { setAttr ($each + ".rotateX") ($rotx); } if ($grp2Y ==1) { setAttr ($each + ".rotateY") ($roty); } if ($grp2Z ==1) { setAttr ($each + ".rotateZ") ($rotz); } } print "Rotation Complete \n" ; } //TRANSLATE PROC global proc ranTrans(float $minVal, float $maxVal){ //Makes $minVal a negative number //$minVal = $minVal*-1; //Selects the objects string $sel[] = `ls -sl`; //create variables from check box group values string $grp2X = (`checkBoxGrp -q -value1 myChkBxGrp2`); string $grp2Y = (`checkBoxGrp -q -value2 myChkBxGrp2`); string $grp2Z = (`checkBoxGrp -q -value3 myChkBxGrp2`); //For loop to move each object in the selection for ($each in $sel){ float $transX = rand ($minVal, $maxVal); float $transY = rand ($minVal, $maxVal); float $transZ = rand ($minVal, $maxVal); //If the check box is ON translate that axis if ($grp2X ==1) { move -r -ls ($transX)(0)(0)$each; } if ($grp2Y ==1) { move -r -ls (0)($transY)(0)$each; } if ($grp2Z ==1) { move -r -ls (0)(0)($transZ)$each; } } print "Translation Complete \n" ; } //SCALE PROC global proc ranScale(float $minVal, float $maxVal){ //Makes $minVal a negative number //$minVal = $minVal*-1; //Selects the objects string $sel[] = `ls -sl`; //create variables from check box group values string $grp2X = (`checkBoxGrp -q -value1 myChkBxGrp2`); string $grp2Y = (`checkBoxGrp -q -value2 myChkBxGrp2`); string $grp2Z = (`checkBoxGrp -q -value3 myChkBxGrp2`); string $grp3 = (`checkBoxGrp -q -value1 myChkBxGrp3`); //For loop to scale each object in the selection for ($each in $sel){ float $scaleX = rand ($minVal, $maxVal); float $scaleY = rand ($minVal, $maxVal); float $scaleZ = rand ($minVal, $maxVal); float $originalScale[] =`xform -q -r -scale $each`; if ($grp3 ==1) { setAttr ($each + ".scaleX") ($scaleX + $originalScale[0]); setAttr ($each + ".scaleY") ($scaleX + $originalScale[1]); setAttr ($each + ".scaleZ") ($scaleX + $originalScale[2]); } else{ //If the check box is ON scale that axis if ($grp2X ==1) { setAttr ($each + ".scaleX") ($scaleX + $originalScale[0]); } if ($grp2Y ==1) { setAttr ($each + ".scaleY") ($scaleY + $originalScale[1]); } if ($grp2Z ==1) { setAttr ($each + ".scaleZ") ($scaleZ + $originalScale[2]); } } } print "Scaling Complete \n" ; } //Select type of transformation proc based on values of the transform check boxes global proc selType(float $minVal, float $maxVal) { if (`checkBoxGrp -q -value1 myChkBxGrp`) ranRot($minVal, $maxVal); if (`checkBoxGrp -q -value2 myChkBxGrp`) ranTrans($minVal, $maxVal); if (`checkBoxGrp -q -value3 myChkBxGrp`) ranScale($minVal, $maxVal); } //Change button lable proc global proc changeButtonLabel(string $whichButton) { string $labelA; string $labelB; $currentLabel = `button -query -label $whichButton`; $labelA = "Toggle All Axis On"; $labelB = "Toggle All Axis Off"; if ($currentLabel != $labelA) { button -edit -label $labelA $whichButton; checkBoxGrp -e -value1 0 myChkBxGrp2; checkBoxGrp -e -value2 0 myChkBxGrp2; checkBoxGrp -e -value3 0 myChkBxGrp2; } else { button -edit -label $labelB $whichButton; checkBoxGrp -e -value1 1 myChkBxGrp2; checkBoxGrp -e -value2 1 myChkBxGrp2; checkBoxGrp -e -value3 1 myChkBxGrp2; } } //UI begins global proc mdTater(){ if ( `window -exists mdTaterWin` ) { deleteUI mdTaterWin; } else if (`windowPref -ex mdTaterWin`) {windowPref -r mdTaterWin;} // checkbox group window -title "Tater" -widthHeight 360 220 -sizeable 0 mdTaterWin; columnLayout myMainCol; // Translation check box groups checkBoxGrp -numberOfCheckBoxes 3 -label "select type:" -adj 3 -cw 1 80 -cw 2 80 -cw 3 80 -cl3 "left" "left" "left" -ct3 "left" "left" "left" -co3 0 0 0 -labelArray3 "Rotation" "Translation" "Scale" myChkBxGrp; //setParent ..; separator -height 10 -width 360 -style "in"; // Axis check box groups checkBoxGrp -numberOfCheckBoxes 3 -label "select Axis:" -adj 3 -cw 1 80 -cw 2 80 -cw 3 80 -cl3 "left" "left" "left" -ct3 "left" "left" "left" -co3 0 0 0 -labelArray3 "X" "Y" "Z" myChkBxGrp2; //button to toggle axis on/off string $button = `button -label "Toggle All Axis On" myBtn1`; //create a proc to toggle state of Axis check boxes. button -edit -command ("changeButtonLabel " + $button ) $button; //setParent ..; //Uniform scaling checkbox separator -height 10 -width 360 -style "in"; checkBoxGrp -numberOfCheckBoxes 1 -label "Scale Uniformly" -adj 1 -cw 1 80 myChkBxGrp3; //setParent ..; //Min and Max value float fields separator -height 10 -width 360 -style "in"; rowLayout -nc 2 -cw2 60 60 myFirstRow; text -l "Min"; text -l "Max"; setParent ..; rowLayout -nc 4 -cw4 60 60 60 60 mySecondRow; //stuff the floatField in a variable string $floatFieldMin = `floatField -v 0 -step 1 -precision 2`; string $floatFieldMax = `floatField -v 0 -step 1 -precision 2`; //button calls a string to assign the user input value from UI into values that can be used for Tater proc arguments button -l "Do It Now!" -command ("float $min = `floatField -q -v "+$floatFieldMin+"`; float $max = `floatField -q -v "+$floatFieldMax+"`; selType($min, $max);"); setParent ..; // separator -height 10 -width 360 -style "in"; text -l "Set Min and Max values and select the Axis and type of Transform"; text -l "desired. Hit the Do It Now! button to execute the randomness."; showWindow mdTaterWin; } mdTater;