Issues in Creating a Simple angular array dialog

Issues in Creating a Simple angular array dialog

Anonymous
Not applicable
570 Views
4 Replies
Message 1 of 5

Issues in Creating a Simple angular array dialog

Anonymous
Not applicable
As a beginner i have been trying to write a mel script to perform a simple angular array generated from a dialog where i can enter the variables. The problem i have now is trying to combine the function of the array and its variable to the UI dialog.

i am able to create a UI dialog on its own with no functionality attached as follows:

// control box

window
-title "Array Parameters"
-widthHeight 500 200;
columnLayout;

string $hyp= `intFieldGrp -label "Distance from origin:"`;
string $total= `intFieldGrp -label "Total number of objects:"`;
string $height= `intFieldGrp -label "Height from Origin:"`;

button -label "Create";

showWindow;

//i am also able to create an angular array as a pure MEL script with a simple prompt Dialog for the basename of the arrayed objects

//radial array01
float $hyp=10;
int $total=20;
int $height=5;
float $startAngle = 0;

float $incAngle = 360/$total;
float $rad=3.141592654/180;


string $baseName;

string $result3 = `promptDialog
-title "Enter Object Name"
-message "Object Name:"
-button "OK"
-button "Cancel"
-defaultButton "OK"
-cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result3 == "OK")
{
$baseName = `promptDialog -q`;

string $sel[] = `ls -sl`;

for($z=0;$z<$total;$z++)
{

float $transX = $hyp*cos(($startAngle+($incAngle*$z))*$rad);
float $transZ = $hyp*sin(($startAngle+($incAngle*$z))*$rad);

string $dup[] = `duplicate -rr $sel`;
string $name = ($baseName+"_"+$z);
rename $dup $name;
move -r $transX $height $transZ $name;

}
}

to the world of experts out there, how am i able to complete my goal?

Thank you very much
0 Likes
571 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
the ui and the array procedures have to be separate.....as an example I re-did your script...... It now has two separate procedures. The ui appears when the command " createArrayUI " is run. It creates the window with the controls and the button that executes the arrayMe procedure. The arrayMe() procedure queries the ui for the user controls (the sliders) settings and preforms the actual array creation based on the state of the window's control settings at that instant.


proc arrayMe(){
string $sel[] = `ls -sl`;
float $startAngle = 0.0;
float $hyp = `floatSliderGrp -q -v radiusSlider`;
int $total = `intSliderGrp -q -v numSlider`;
float $height = `floatSliderGrp -q -v heightSlider`;
float $incAngle = 2 * 3.141592654 / $total;

int $i;
for($i=0;$i<=$total;++$i){
float $transX = $hyp*cos($i * $incAngle);
float $transZ = $hyp*sin($i * $incAngle);
string $dup[] = `duplicate -rr $sel`;
move -r $transX $height $transZ $dup;
}
}

global proc createArrayUI(){
window -title "Array Parameters" -widthHeight 500 200 arrayCreator;
columnLayout;
floatSliderGrp -label "Distance from origin:"
-field true
-minValue 1.0 -maxValue 10.0
-fieldMinValue 0.0 -fieldMaxValue 100.0
-value 10
radiusSlider;

intSliderGrp -label "Total number of objects:"
-field true
-minValue 2 -maxValue 100
-fieldMinValue 2 -fieldMaxValue 1000
-value 10
numSlider;

floatSliderGrp -label "Height from Origin:"
-field true
-minValue -10.0 -maxValue 10.0
-fieldMinValue -100.0 -fieldMaxValue 100.0
-value 0
heightSlider;

button -label "Create" -w 400 -h 25 -c "arrayMe" createArrayButton;
showWindow arrayCreator;
}
0 Likes
Message 3 of 5

Anonymous
Not applicable
Thank you Paulalso, i have only just started to get into maya, so just looking here and there for tutorials and also looking at how other people's scripts are applied, your help was very helpful, i now understand more how UI should be put together.
0 Likes
Message 4 of 5

Anonymous
Not applicable
just found out that you can use cosd and sind functions instead of converting coz and sin to radians
0 Likes
Message 5 of 5

Anonymous
Not applicable
that's a good way to learn mel...just keep scanning the docs...and writing little bits of code....reuse all that you can....
0 Likes