//Here is a mel scripts I wrote. It is for duplicating objects randomly.
//Have a fun with it!!!

//copier.ver 1.0
//Author: Jaetaek Hwang
//Date: May 04, 2009
//selects objects and make it a array
string $my_selectedObjects[] = `selectedNodes`;
$sizeSelected = size($my_selectedObjects);
if($sizeSelected == 0)
{
confirmDialog - title "confirm"
- message "Please select at least one object."
-button "Exit";
error "You should select at least one object!!!";
}
else
{
makeGUI(); //calls GUI
}
//makes copies of the selected objects and closes windows by the OK button.
global proc makeCopy()
{
global string $my_positionX_min, $my_positionX_max, $my_positionY_min, $my_positionY_max, $my_positionZ_min, $my_positionZ_max;
global string $my_rotateX_min, $my_rotateX_max, $my_rotateY_min, $my_rotateY_max, $my_rotateZ_min, $my_rotateZ_max;
global string $my_scaleX_min, $my_scaleX_max;
global string $my_num_bladeSlider;
int $selected;
int $sizeSelected;
//global int $total;
string $my_selectedObjects[] = `selectedNodes`;
int $sizeSelected = size($my_selectedObjects);
string $my_selectedObjects[];
float $pX_min = `floatSliderGrp -q -value $my_positionX_min`;
float $pX_max = `floatSliderGrp -q -value $my_positionX_max`;
float $pY_min = `floatSliderGrp -q -value $my_positionY_min`;
float $pY_max = `floatSliderGrp -q -value $my_positionY_max`;
float $pZ_min = `floatSliderGrp -q -value $my_positionZ_min`;
float $pZ_max = `floatSliderGrp -q -value $my_positionZ_max`;
float $rX_min = `floatSliderGrp -q -value $my_rotateX_min`;
float $rX_max = `floatSliderGrp -q -value $my_rotateX_max`;
float $rY_min = `floatSliderGrp -q -value $my_rotateY_min`;
float $rY_max = `floatSliderGrp -q -value $my_rotateY_max`;
float $rZ_min = `floatSliderGrp -q -value $my_rotateZ_min`;
float $rZ_max = `floatSliderGrp -q -value $my_rotateZ_max`;
float $sX_min = `floatSliderGrp -q -value $my_scaleX_min`;
float $sX_max = `floatSliderGrp -q -value $my_scaleX_max`;
//counts a number of blades which will be made
int $max = `intSliderGrp -q -value $my_num_bladeSlider`;
for($selected =0; $selected<$sizeSelected; $selected++)
{
select $my_selectedObjects[$selected];
if(!($max == 0))
{ for( $i=0; $i<$max; $i++)
{
instance;
makePosition($pX_min, $pX_max, $pY_min, $pY_max, $pZ_min, $pZ_max);
makeRotate($rX_min, $rX_max, $rY_min, $rY_max, $rZ_min, $rZ_max);
makeScale($sX_min, $sX_max);
}
}
else
{
warning ("You did not enter a number of blade you want");
confirmDialog - title "confirm"
- message ("0 copy of the " + $my_selectedObjects[$selected] + " will be generated")
- button "Quit";
warning ("0 blade of the " + $my_selectedObjects[$selected] + " was generated. ");
}
}
//print ( $total + " blades were generated."); //counts the total blades you made
}
//close windows by the cancle button.
global proc makeClose()
{
//global int $total;
//print ( $total + " blades were generated.");
print "Good-Bye!!!";
}
//move objects randomly
global proc makePosition(float $pX_min, float $pX_max, float $pY_min, float $pY_max, float $pZ_min, float $pZ_max)
{
float $positionX = rand($pX_min, $pX_max);
float $positionY = rand($pY_min, $pY_max);
float $positionZ = rand($pZ_min, $pZ_max);
move $positionX $positionY $positionZ;
}
//rotate objeccts randomly
global proc makeRotate(float $rotX_min, float $rotX_max,
float $rotY_min, float $rotY_max,
float $rotZ_min, float $rotZ_max)
{
float $rotateX = rand($rotX_min, $rotX_max);
float $rotateY = rand($rotY_min, $rotY_max);
float $rotateZ = rand($rotZ_min, $rotZ_max);
rotate $rotateX $rotateY $rotateZ;
}
//scale objects randomly
global proc makeScale(float $scaX_min, float $scaX_max)
{
float $scaleX = rand($scaX_min, $scaX_max);
scale $scaleX $scaleX $scaleX;
}
global proc makeGUI()
{
int $selected;
string $my_selectedObjects[] = `selectedNodes`;
global string $my_positionX_min, $my_positionX_max, $my_positionY_min, $my_positionY_max, $my_positionZ_min, $my_positionZ_max;
global string $my_rotateX_min, $my_rotateX_max, $my_rotateY_min, $my_rotateY_max, $my_rotateZ_min, $my_rotateZ_max;
global string $my_scaleX_min, $my_scaleX_max;
global string $my_num_bladeSlider;
//string $list = $my_selectedObjects; //makes a object list
$my_window = `window -title ("Copier Ver_1.0")` ;
columnLayout;
separator -st "in" -h 5 -w 800;
frameLayout -label (" "+ ($my_selectedObjects[0]) +" "+ ($my_selectedObjects[1])+ " " + ($my_selectedObjects[2])+ " ")
-la "center"
-li 5;
columnLayout;
$my_num_bladeSlider = `intSliderGrp //a number of copies of blades
-min 0
-max 500
-fieldMinValue 0
-fieldMaxValue 1000
-label "Count (0-1000)"
-columnWidth 1 100 -columnWidth 2 50
-step 1
-field true`;
separator -st "in" -h 5 -w 780;
rowColumnLayout -nc 3
-cw 1 260 -cw 2 260 -cw 3 260
-co 1 "left" 5 -co 2 "left" 5 -co 3 "left" 5
-ro 1 "both" 5 -ro 2 "both" 5 -ro 3 "both" 5;
frameLayout -label "Position"
-labelAlign "center"
-li 10
-mh 5;
columnLayout;
separator -st "in" -h 5 -w 250;
$my_positionX_min = `floatSliderGrp
-min -10.0
-max 10.0
-fieldMinValue -10.0
-fieldMaxValue 10.0
-value -10.0
-label "X.min"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
$my_positionX_max = `floatSliderGrp
-min -10.0
-max 10.0
-fieldMinValue -10.0
-fieldMaxValue 10.0
-value 10.0
-label "X.max"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
separator -st "in" -h 5 -w 250;
$my_positionY_min = `floatSliderGrp
-min -10.0
-max 10.0
-fieldMinValue -10.0
-fieldMaxValue 10.0
-value -10.0
-label "Y.min"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
$my_positionY_max = `floatSliderGrp
-min -10.0
-max 10.0
-fieldMinValue -10.0
-fieldMaxValue 10.0
-value 10.0
-label "Y.max"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
separator -st "in" -h 5 -w 750;
$my_positionZ_min = `floatSliderGrp
-min -10.0
-max 10.0
-fieldMinValue -10.0
-fieldMaxValue 10.0
-value -10.0
-label "Z.min"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
$my_positionZ_max = `floatSliderGrp
-min -10.0
-max 10.0
-fieldMinValue -10.0
-fieldMaxValue 10.0
-value 10.0
-label "Z.max"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
separator -st "in" -h 5 -w 250;
setParent ..;
setParent ..;
frameLayout -label "Rotate"
-labelAlign "center"
-li 10
-mh 5;
columnLayout;
separator -st "in" -h 5 -w 750;
$my_rotateX_min = `floatSliderGrp
-min -30.0
-max 30.0
-fieldMinValue -40.0
-fieldMaxValue 40.0
-value -30.0
-label "X.min"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
$my_rotateX_max = `floatSliderGrp
-min -30.0
-max 30.0
-fieldMinValue -40.0
-fieldMaxValue 40.0
-value 30.0
-label "X.max"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
separator -st "in" -h 5 -w 750;
$my_rotateY_min = `floatSliderGrp
-min 0.0
-max 360.0
-fieldMinValue 0.0
-fieldMaxValue 360.0
-value 0.0
-label "Y.min"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
$my_rotateY_max = `floatSliderGrp
-min 0.0
-max 360.0
-fieldMinValue 0.0
-fieldMaxValue 360.0
-value 360.0
-label "Y.max"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
separator -st "in" -h 5 -w 750;
$my_rotateZ_min = `floatSliderGrp
-min -30.0
-max 30.0
-fieldMinValue -40.0
-fieldMaxValue 40.0
-value -30.0
-label "Z.min"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
$my_rotateZ_max = `floatSliderGrp
-min -30.0
-max 30.0
-fieldMinValue -40.0
-fieldMaxValue 40.0
-value 30.0
-label "Z.max"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
separator -st "in" -h 5 -w 250;
setParent ..;
setParent ..;
frameLayout -label "Scale"
-labelAlign "center"
-li 10
-mh 5;
columnLayout;
separator -st "in" -h 5 -w 250;
$my_scaleX_min = `floatSliderGrp
-min .1
-max 1.9
-fieldMinValue .1
-fieldMaxValue 1.9
-value .8
-label "X.min"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
$my_scaleX_max = `floatSliderGrp
-min .1
-max 1.9
-fieldMinValue .1
-fieldMaxValue 1.9
-value 1.2
-label "X.max"
-columnWidth 1 48 -cw 2 44 -cw 3 30
-width 260
-field true`;
separator -st "in" -h 5 -w 250;
setParent ..;
setParent ..;
setParent ..;
//makes buttons
separator -st "in" -h 5 -w 780;
rowColumnLayout -nc 6 -cw 5 60 -cw 6 60;
button -label "Make Copy" -align "center" -command ("makeCopy(); deleteUI " + $my_window);
button -label "Apply" -align "center" -command "makeCopy()";
button -label "Close" -align "center" -command ("makeClose(); deleteUI " + $my_window);
text " ";
button -label "Undo" -align "center" -command "undo; ";
button -label "Redo" -align "center" -command "redo; ";
setParent;
showWindow $my_window;
}