PDA

View Full Version : MEL - Further education!


BadG3r
11-07-2006, 09:55 AM
Hi!

On what scripting language is MEL based on???

Cause right now I'm trying to get into MEL, but still I have problems with Syntax and such things. When do I use quotes when other things and so on...


Thx in advance,
BadG3r

meljunky
11-07-2006, 03:08 PM
I am not sure what language MEL is based off of.

Complete Maya Programming is a good book to learn MEL, also if you can find cache versions of Bryan Ewert old web site, formally http://www.ewertb.com/ there is great information available for MEL. I used the help docs to learn MEL too... random searches for various commands what fun. Reverse engineering scripts is usefull when matched up with the MEL Command Reference.

When ever you deal with string, is where you need quotes. String being alphanumeric for those who don't know. When adding a variable you need the following format ("Hello " + $world)

A good text eding program like Context combine with the MEL Highlighter helps to find syntax errors.

Robert Bateman
11-07-2006, 04:15 PM
mel is closely related to TCL/Tk with a few differences.

given a proc :


proc int foo() {
return 1;
}


to call that func you can do,


foo;

// or

foo();


to get the result of that call into a variable, you can do :


$var = `foo`;

// or

$var = foo();


This also applies to the variable parameter type functions of mel, so to get the current selection list, you can do :


$objects = `ls -selected`;

// or

$objects = ls("-selected");


My site also has a few bits and bobs about mel on it....

dbmata
11-08-2006, 10:14 PM
My site also has a few bits and bobs about mel on it....


Definitely check out Rob's site, it's helping me from completely tearing my hair out.

Good at teaching a lot of the more basic stuff, from what I've been told. I'm still having a rough go of it.

BadG3r
11-09-2006, 01:53 PM
Well guys thanks.

Of course I hit another prob.

Heres the script:

//create a cloud with the radius of 3 containing 100 particles

for ($x=0; $x<100;$x++)
{

vector $pos = sphrand (3);

particle -position ($pos.x) ($pos.y) ($pos.z);

}

// now change the render type to spheres

select -all;
string $particles[] = `ls -sl`;
int $evPa;

for ($evPa=1; $evPa < size ($particles); $evPa++) {

setAttr ("particleShape" + $evPa).particleRenderType 4;

}




Heres the problem:
When I try to declare the particleShape-Node it returns me an error.

Error: No attribute was specified.

Here's the question:

How do I have to write it so I can access all Shape nodes????
Because naming each single one is a fun job for monkeys but not for me.
And please dont tell me: Hey its time to get some monkey! ;)


Thx in advance
BadG3r

goleafsgo
11-09-2006, 02:31 PM
setAttr ("particleShape" + $evPa).particleRenderType 4;

should probably be

setAttr ("particleShape" + $evPa + ".particleRenderType") 4;

And the "select -all" will actually select things that you don't want. Since you have a hardcoded number that you are creating then you probably don't need to select everything just to get the count do you?

You could probably just do this:


for ($x=0; $x<100;$x++)
{
vector $pos = sphrand (3);
string $particleName[] = `particle -position ($pos.x) ($pos.y) ($pos.z)`;
setAttr ($particleName[1] + ".particleRenderType") 4;
}

BadG3r
11-09-2006, 03:17 PM
setAttr ("particleShape" + $evPa).particleRenderType 4;

should probably be

setAttr ("particleShape" + $evPa + ".particleRenderType") 4;



Ahh ok, i see.

So i have to set everything with characters in quotes + the variables... ok.





You could probably just do this:


for ($x=0; $x<100;$x++)
{
vector $pos = sphrand (3);
string $particleName[] = `particle -position ($pos.x) ($pos.y) ($pos.z)`;
setAttr ($particleName[1] + ".particleRenderType") 4;
}



k i can read it and I mostly understand it BUT...
Why is this working???

I mean: I thought the backticks say: `Take what ever is in here`
Why do they execute the line???

Thx man.

goleafsgo
11-09-2006, 03:21 PM
When you call a MEL command with the `'s around it it just executes the command and stores the result in your variable.

BadG3r
11-09-2006, 03:49 PM
Ok, so if I don't want it to excute I need to use -query, right???

and by the way: how do I get the position of a sphere???

I was typing anyway right now and I searched my ass off.
Maybe pretty basic but all this scripting makes me whizziy-dizzy in the head.

Thx again.

Robert Bateman
11-09-2006, 05:56 PM
and by the way: how do I get the position of a sphere???

To get the position, rotation or scale of anything, you need to query it's transform values. You could do this using getAttr if you don't mind local spae values. Otherwise (and probably better anyway) is to use the xform command, ie :

$pos = `xform -q -ws -t "pSphere1"`;

BadG3r
11-09-2006, 08:15 PM
To get the position, rotation or scale of anything, you need to query it's transform values. You could do this using getAttr if you don't mind local spae values. Otherwise (and probably better anyway) is to use the xform command, ie :

$pos = `xform -q -ws -t "pSphere1"`;


thx. this nearly blew my mind.

xform... i remember that I read something somewhere :)

til the next session of "BadG3r learns MEL"

thx to you all :thumbsup:

CGTalk Moderation
11-09-2006, 08:15 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.