Hello everyone!
I'm quite new to mel but got this assigment in school recently. Its suposed to create a nurbs curve helix and its optional to use an UI window with a number of extra options.
Usually i just write as i think I should and then I "debug" the script by testing it, fixing errors along the way.
This time, however I just can't find the problem. I'm pretty sure you should be able to use the variable that drives a loop in the loop itself like for ( $i=0; $i<8; $i++ {print $i;} and I'm guessing a loop in the loop can use the main loops variable like for ( $i=0; $i<8; $i++ { for ( $p=0; $p<8; $p++ {print $i*$p;}}. So wh won't my script work? plz help!
Oh and btw. the formula for calculating the helix might be wrong at the moment but that's something i intend to fix as soon I get this main proc to work.
Thanx in advance!
SCRIPT -->
proc Nurbix() {
if ( window -exists NurbixGUI)
deleteUI NurbixGUI;
window
-title "Nurbix curve creator 1.0"
-s 0
NurbixGUI;
formLayout
-numberOfDivisions 100
myForm;
floatSliderGrp -label "Smoothness" -value 3 -field 1 -cw 1 80 -cw 2 30 -cw 3 10
-minValue 1 -maxValue 10 -fieldMinValue 1 -fieldMaxValue 10 floatSlideGrpOne;
floatSliderGrp -label "Upper radius" -value 1 -field 1 -cw 1 80 -cw 2 30 -cw 3 10
-minValue 0.1 -maxValue 10 -fieldMinValue 0.1 -fieldMaxValue 10 floatSlideGrpTwo;
floatSliderGrp -label "Lower radius" -value 1 -field 1 -cw 1 80 -cw 2 30 -cw 3 10
-minValue 0.1 -maxValue 10 -fieldMinValue 0.1 -fieldMaxValue 10 floatSlideGrpThree;
floatSliderGrp -label "Height" -value 3 -field 1 -cw 1 80 -cw 2 30 -cw 3 10
-minValue 0.1 -maxValue 20 -fieldMinValue 0.1 -fieldMaxValue 20 floatSlideGrpFour;
intSliderGrp -label "turns 360" -value 3 -field 1 -cw 1 80 -cw 2 30 -cw 3 10
-minValue 1 -maxValue 30 -fieldMinValue 1 -fieldMaxValue 30 intSlideGrpOne;
floatSliderGrp -label "Density/turn" -value 10 -field 1 -cw 1 80 -cw 2 30 -cw 3 10
-minValue 4 -maxValue 20 -fieldMinValue 4 -fieldMaxValue 20 floatSlideGrpSix;
iconTextButton -w 110 -style "iconAndTextHorizontal"
-image "polyhelix.xpm" -label "Create curve" -command mainproc IconButtonGrpOne;
formLayout
-edit
-attachForm floatSlideGrpOne "top" 2
-attachForm floatSlideGrpTwo "top" 22
-attachForm floatSlideGrpThree "top" 42
-attachForm floatSlideGrpFour "top" 62
-attachForm intSlideGrpOne "top" 82
-attachForm floatSlideGrpSix "top" 102
-attachForm IconButtonGrpOne "top" 122
-attachForm IconButtonGrpOne "left" 72
myForm;
float $smooth;
float $uRadius;
float $height;
int $turns;
float $density;
string $nurbixCurve;
float $zInc;
float $degree;
float $x;
float $y;
float $z;
showWindow;
}
proc mainproc() {
$smooth = floatSliderGrp -q -value floatSlideGrpOne;
$uRadius = floatSliderGrp -q -value floatSlideGrpTwo;
$lRadius = floatSliderGrp -q -value floatSlideGrpThree;
$height = floatSliderGrp -q -value floatSlideGrpFour;
$turns = intSliderGrp -q -value intSlideGrpOne;
$density = floatSliderGrp -q -value floatSlideGrpSix;
$nurbixCurve = "curve -d " + $smooth;
$zInc = ($height/$turns)/$density;
$degree = 360/$density;
$x = 0;
$y = 0;
$z = 0;
for ( $i=0; $i<$turns+1; $i++ ){
for ( $p=0; $p<$density+1; $p++ ){
$x = cos($p*$degree-$degree);
$z = sin($p*$degree-$degree);
$y = ($zInc*$p)+($zInc*$density*($i-1));
$nurbixCurve = $nurbixCurve + " -p " + $x + " " + $y + " " + $z;
}
}
}
Nurbix
