View Full Version : New To Mel - Quick Question

07 July 2007, 03:17 AM
Hello everyone,

Im teaching myself MEL and having a bit of trouble executing a script which I found in a help guide. I cant work out what the problem is?

Does someone know what is wrong with the below script?

Thankyou so much.

1 global proc fractal()[
3 vector $generator[]; //make an array for the generator
4 $generator=getPoints("curve1"); //populate the array with the curve1 (generator)points
5 vector$base[]; //make an array for the base
7 string $list[];
8 $list = eval("Is -transforms\"curve*\""); //returns an array with the names of
9 //all objects in he scene that match the word "curve"
11 for($j=1;$j<size($list);$j++){ //we start at 1 because 0 is the generator
12 $base_name = $list[($j)];
14 $base = getPoints($base_name); //get the points
15 //once we have the points we erase the shape since we will replace it
16 eval("delete " + $base_name);
18 for($i=0; $i<(size($base)-1); $i++)
19 // replace the current (i) and the next (i+1) points with the generators array
20 fit($base[$i], $base[($i+1)], $generator);
21 } //for j
22} // procedure end

07 July 2007, 11:32 PM
hi, i did not check the entire thing, also because of the line numbers which make it difficult to quickly copy and test.
but here's a typo

global proc fractal()[

it should look like this:
global proc fractal(){

07 July 2007, 10:48 AM
thanks alot!

im still learnng so picking up things as i go along.


07 July 2007, 11:32 AM
thanks pix,

i have tried what you say but am still getting an error stating error for line 21.2 'syntax error'

it looks ok to me?

07 July 2007, 06:53 PM
Remember when you get an error and it tells you the line: it is the line that maya bombs out on. It does not *have* to be the line that has the actual error.

That said, I suspect the line prior to it. "fit" is not a standard maya call. That means it is your function and probably has an error in it. You'll have to post the code for your "fit" procedure.

This brings me to a second point. It is helpful for you to provide a working example else we can only correct syntactical not logical errors. You should also post the code for your getPoints().

From the current post the only mel syntax problem is the missing space between "vector" and "$base" in the beginning (and the correction mentioned by pix). This, of course, assumes that getPoints() and fit() work properly, which they probably don't.

07 July 2007, 09:11 PM
It looks like you're missing some '{' at the start of your for loops.

for ($j=1;$j<size($list);$j++)
{ // this curly bracket was missing

$base_name = $list[($j)];
$base = getPoints($base_name);
eval("delete " + $base_name);

for ($i=0; $i<(size($base)-1); $i++)
{ // this curly bracket was missing

fit($base[$i], $base[($i+1)], $generator);

07 July 2007, 09:20 PM
also, you'll need to enclose your generator statement in the ` ` things, since you're executing a command to get a value.

Like so:

$generator = `getPoints("curve1")`;

07 July 2007, 09:30 PM
lol don't listen to Norb!

Norb: when you call a function that returns a value such as her function getPoints() you DO NOT put it in backticks (``) to capture the value.

The second for loop DOES NOT require open and closing braces. In programming if you leave out the braces then the next line is included in the loop

for($obj in $objects)
print ("this works!\n);

The first bracket ([) should be an open brace ({) but she has already fixed that.

07 July 2007, 10:04 PM
Yo harmless, chill. Norb is/was probably a java / javascript / pearl / cgi / c++ / c / php / css / xhtml / dhtml / asp coder before. I use {} on everything even though it isn't needed. I NEVER trust that no bracket thing in mel, NEVER.

07 July 2007, 01:36 AM
Norb: when you call a function that returns a value such as her function getPoints() you DO NOT put it in backticks (``) to capture the value.

Care to explain why, oh mighty mel guru? As far as I was told, anything in the backticks gets executed, so what's wrong with putting the command in there? It still returns the value needed, does it not?

07 July 2007, 01:53 AM
It does work.
Backquotes were designed to evaluate expressions. Placing them around a call to a function evaluates a function that is already being called.

In this case: $myCube = `polyCube`; it *has* to be used.

07 July 2007, 12:00 PM
guys thankyou all for your words, and already im slowly picking things up.

however, when executing the script I dont get error messages any more (great!) but nothing is generated. why?

i get this error when i run the corrected script (below)

Cannot find procedure "getPoints".
Start of trace: (command window: line 4).
getPoints (command window: line 4).
fractal (command window: line 1).


global proc fractal(){
vector $generator[];
string $list[];
$list = eval("Is -transforms\"curve*\"");
for($j=1;$j<size($list);$j++) {
$base_name = $list[($j)];
$base = getPoints($base_name);
eval("delete " + $base_name);
for($i=0; $i<(size($base)-1); $i++)
fit($base[$i], $base[($i+1)], $generator);

07 July 2007, 12:25 PM
your script seems out of context.
your are missing the getpoints function - this seems to be a custom function, so you need the source code of it.

07 July 2007, 02:07 PM
Pix is right. You also need the source for "fit". It is not a standard maya call.

08 August 2007, 11:34 AM
yeah finally worked it out.

one more question before I hit the scripting manual...

i have got this script clean and executable (as in no errors) and its suppose to create a hybrid object between to objects however its not.

Can you suggest what to do to make it work?

global proc hybrid(string $parent1, string $parent2, float $ratio){
int $p1pnts = eval("getAttr "+ $parent1 + ".spans");
int $p2pnts = eval("getAttr "+ $parent2 + ".spans");
int $degree = eval("getAttr "+ $parent2 + ".degree");
int $numpoints = max($p1pnts, $p2pnts);
int $k1 = 0;
int $k2 = 0;
string $spoints ="";
float $point[];
for($k=0; $k<($numpoints+1); $k++){
$k1 = $k;
$k2 = $k/(($p1pnts*1.)/($p2pnts*1.));}
else {
$k1 = $k/(($p2pnts*1.)/($p1pnts*1.));
$k2 = $k;}
$p1 = eval("pointPosition"+$parent1 +" .cv["+$k1+"]");
$p2 = eval("pointPosition"+$parent2 +" .cv["+$k2+"]");
$point[$j] = $p1[$j] + $ratio * ($p2[$j] - $p1[$j]);
$spoints += "-p" + $point[0] +"" + $point[1] +"" + $point[2];
eval("curve-d" + $degree + ""+$spoints);

08 August 2007, 04:28 PM
It looks like it makes a new curve when given 2 curves and a ratio.
It doesn't work because there is a call to the function "pointPosition()" which is a custom function, not an internal maya function.

To get this to work you'd have to have the source code for "pointPosition()" and pass in 2 strings and a ratio to the original function.

On another note, try going through maya's documents. They really are quite good. You will learn a lot. We are here to help you when you get stuck.

08 August 2007, 05:53 PM
Uh, looking at your code, I'm not too sure about

$p1 = eval("pointPosition"+$parent1 +" .cv["+$k1+"]");
$p2 = eval("pointPosition"+$parent2 +" .cv["+$k2+"]");
this is also a space between the +" .cv

you don't need to evaluate that statement

$p1 = `pointPosition ($parent1 +".cv["+$k1+"]")`;
$p2 = `pointPosition ($parent2 +".cv["+$k2+"]")`;

that should do it, because I think it is looking at your parent variables and it's linking it with pointPosition.

Derek Wolfe
08 August 2007, 07:18 PM
pointPosition is a standard mel command that returns the world or local position of a point. Valid points include control vertices, as used in this script.

CGTalk Moderation
08 August 2007, 07:18 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.