It Just Won't Work

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

Yes but very bad strategy your kind of doing in mel what the api is for and thats allways bad. So you dont do mel like this except in emergency. So yes its a mel script but not mel scripting at its best.

read maya\scripts\unsupported\spiral.mel

It has a better approach, that uses history. This way you can LATER change the helix parameters from within the channelbox so you can actually animate the the attributes later. Wich s MUCH MUCH more valuable then learning how to brute force.

Idea is to put a linear curve on a cylinder and then make the cylinder inetrmeiate and duplicate the resulting spiral. Off course maya allredy has a spiral node. Anyway invetsigate this old trick and you get a gui for free, as maya instinctively know to make it.

So my advice is ditch what you have. and start over with the better apporach its not only shorter its way way better as it gives added value to users. And youlearn the power of how mel is really used. Better yet you dont waste time designinga gui but actually focusing on the goal.


PS:
if your teacher does not bring this fact up (he probably will after your assignemnts or you jsut misse dit) then hes not really worth his salary as a mel teacher *. Mels idea is tu build with nodes.

  • You can quote me on that as long as you smile. I fix teachings like this EVERY day.

**when your done i can do you a reference solution to match up by.

Thanx! I see your point

What you describes seems alot more advanced but i realize its way smarter and I will learn alot more from it. Not sure I'll have the time before my deadline though. I will have a looka right away..

Thanx again!

QUOTE(Holoshark @ 06/16/09, 11:35 AM) [snapback]309588[/snapback]
Not sure I'll have the time before my deadline though. I will have a looka right away..

It actually much, much shorter you should have it sorted in half an hour or so. the example with maya is 7 nines but hooking it to manipulation is about 7 more.

Its about quality of code not quantity

I checked the script out and it was really brilliant. was just going to create an UI for the script when i read my instructions again. I guess the teacher knows all about this cylinder technique but he wrote, "write a script creating a nurbs spiral with the help of the curve command and for loops ;:frowning:

Guess I still need my old "crude" script then. Allthough I still can't figure out why it won't work.

QUOTE(Holoshark @ 06/16/09, 01:29 PM) [snapback]309595[/snapback]
"write a script creating a nurbs spiral with the help of the curve command and for loops ;:frowning:

Well hes trying to illustrate for loops. But doenst really count for the bad consequences such things end up doing to you. And has not really comes in terms where its is to be used

In any case dont conatenate a string. make a signe point curve then append points to that curve after the fact. Something a bit like this classic example (thet beraks all the rules of mel scipting done in style, its been since nicknamed the Joojaa soda can. Didint name it myself. just quoting myself to save time):

CODE
{
file -f -new;
$pnts={<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>,
<>};
setAttr "persp.translateX" 6;
setAttr "persp.translateY" 25;
setAttr "persp.translateZ" 25.;
setAttr "persp.rotateX" -34;
setAttr "persp.rotateY" 14;
setAttr "persp.rotateY" 14;
setAttr "persp.rotateZ" 0;
setAttr "persp.scaleX" 1;
setAttr "persp.scaleY" 1;
setAttr "persp.scaleZ" 1;
modelEditor -edit -displayAppearance smoothShaded -activeOnly false modelPanel4;
$crv=curve -d 3 -p 0 12.762147 0;
refresh;
for ($vect in $pnts){
curve -ws -a -p ($vect.x) ($vect.z+12.762147) ($vect.y) $crv;
refresh;
}
pause -sec 1;
revolve  -ch 1 -po 0 -rn 0 -ssw 0
       -esw 15 -ut 0 -tol 0.01
       -degree 3 -s 8 -ulp 1
       -ax 0 1 0 $crv;
for ($i=30;$i<=360;$i=$i+15){
setAttr "revolve1.endSweep" $i;
refresh;
}
}

Pay attention to:

CODE
$crv=curve -d 3 -p 0 12.762147 0;
for ($vect in $pnts){
curve -ws -a -p ($vect.x) ($vect.z+12.762147) ($vect.y) $crv;
}

See how i actually add points using a separate command and no need to veal