PDA

View Full Version : Mel Script HELP.


Itzhyxithyl
10-27-2007, 12:57 PM
Im NoObiE! trying to learn MEL and trying to write a simple program that creates spheres, you should be able to change how many you want to create with a slider and when you click OK button the loop starts, here is the code i have so far....but cant figure out how have the slider connected to variable $myNum....how?


//==========================================================
window;
columnLayout;
intSliderGrp -label "How Many Spheres?" -field true
-fieldMinValue -0 -fieldMaxValue 200
-minValue -0 -maxValue 200 -value 0;
button -label "OK" -command "runTheProgram" BangButton;
showWindow;

// PROC LOOP WHEN YOU CLICK OK? VARIABLES NEED TO BE INSIDE THE PROC?
proc runTheProgram()
{

// VARIABLES
int $myNum = 10;
float $thickness = .5;
int $laps = 0;

// LOOP
while ( $laps <= $myNum ){

sphere;
move 0 $laps 0;
scale 1 $thickness 1;

$laps++;
print $laps;
print " DONE\n";
}
}
//=============================================================

sloggo
10-27-2007, 01:13 PM
the key is to separate the UI in to a seperate proc entirely.

if you put the variables and the loop parts within the Run procedure and then group the window stuff as a proc as well then you should be good. also you'll want to query the values from your UI to get the Variables inside your proc.

some really quick changes to what you've got there might be:

//================================================== ========
global proc myNewSphereUI(){
window;
columnLayout;
floatSliderGrp -label "How Many Spheres?" -field true
-fieldMinValue -50 -fieldMaxValue 50
-minValue -10 -maxValue 10 -value 0 mySphereValue;
button -label "OK" -command "runTheProgram" BangButton;

showWindow;
}




// PROC LOOP WHEN YOU CLICK OK? CANT RUN LOOP INSIDE HERE?
global proc runTheProgram()
{

// VARIABLES
int $myNum = `floatSliderGrp -q -value mySphereValue`;
float $thickness = .5;
int $laps = 0;

// LOOP
while ( $laps <= $myNum ){

sphere;
move 0 $laps 0;
scale 1 $thickness 1;
$laps++;
}

print "DONE\n";
}


//================================================== ===========





See how that goes...

see that Ive named the float slider in there as well so that you can query it later in the proc.

some other things to think about would be to add UI controls for the other variables so that you can set them as well in the same way. for the control you have there it should be some sort of int slider instead of a float( you cant create 5.3 spheres, for instance. You want whole numbers) and also make the minValue 0( currently setting a negative value on that slider will do reallll nasty things, your proc will never end.)

good luck

Itzhyxithyl
10-27-2007, 01:29 PM
I added that code but still cant get it to work, can you try run this in maya and see whats wrong, the program dosnt start now when i added the global proc line.

//==========================================================
global proc myNewSphereUI(){
window;
columnLayout;
intSliderGrp -label "How Many Spheres?" -field true
-fieldMinValue -0 -fieldMaxValue 200
-minValue -0 -maxValue 200 -value 0;
button -label "OK" -command "runTheProgram" BangButton;
showWindow;
}

// PROC LOOP WHEN YOU CLICK OK? VARIABLES NEED TO BE INSIDE THE PROC?
proc runTheProgram()
{
// VARIABLES
int $myNum = `intSliderGrp -q -value mySphereValue`;
float $thickness = .5;
int $laps = 0;
// LOOP
while ( $laps <= $myNum ){
sphere;
move 0 $laps 0;
scale 1 $thickness 1;
$laps++;
print $laps;
print " DONE\n";
}
}
//=============================================================

sloggo
10-27-2007, 01:31 PM
runs fine for me. run that code there, then enter "myNewSphereUI" in your command line

Itzhyxithyl
10-27-2007, 01:35 PM
Ok it started but i get a // Error: // when i click ok?

sloggo
10-27-2007, 01:37 PM
oh right, change this part:

"intSliderGrp -label "How Many Spheres?" -field true
-fieldMinValue -0 -fieldMaxValue 200
-minValue -0 -maxValue 200 -value 0;"

to

intSliderGrp -label "How Many Spheres?" -field true
-fieldMinValue -0 -fieldMaxValue 200
-minValue -0 -maxValue 200 -value 0 mySphereValue;


thats what I was talking about naming the slider control so you can query it later.

Itzhyxithyl
10-27-2007, 01:46 PM
Sweet thanks i get it now , but it creates one more sphere than it should, need to change someting in the loop =)

sloggo
10-27-2007, 01:53 PM
no probs.
to fix that extra one problem either declare $laps as 1 instead of 0
OR
change the <= to an <

CGTalk Moderation
10-27-2007, 01:53 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.