Differences between expression and MEL syntax

 
 
 

There are only two differences between expression and MEL syntax: direct access of object attributes, and the use of the time and frame variables.

Direct access to object attributes

In an expression, you can directly access object attributes where as in MEL you must use the getAttr, setAttr, getParticleAttr, or setParticleAttr commands.

The following are some examples of expression syntax that directly accesses object attributes.

persp.translateX = 23.2;
float $perspRotX = persp.rotateX;

To do something like the above in MEL you would have to use the setAttr and getAttr commands as the following examples illustrate.

setAttr("persp.translateY", 23.2);
float $perspRotY = getAttr("persp.rotateY");

Execute the following command in the Script Editor to create a couple particles:

particle -position 1 2 3 -position 2 1 3 -name dust;

now you can use the following expression syntax for the particle shape:

vector $pos = position;
acceleration = <<2, 1, 0>>;

To do something like the above in MEL you would have to use the setParticleAttr and getParticleAttr commands as the following examples illustrate.

select dustShape.pt[0];
 float $temp[] =
 getParticleAttr("-attribute", "position", "dustShape.pt[0]");
 vector $position = <<$temp[0], $temp[1], $temp[2]>>;
 setParticleAttr("-attribute", "velocity", "-vectorValue",
 -3, 0, 0, "dustShape.pt[0]");

The above MEL commands are only for the first particle in the particleShape.

time and frame variables

In an expression, you can use the time and frame predefined variables. For example:

persp.translateY = frame;
persp.rotateY = time;

You can’t use time and frame in MEL. To access time and frame information in MEL, you have to do something like the following:

float $frame = `currentTime -q`;
string $timeFormat = `currentUnit -query -time`;
currentUnit -time sec;
float $time = `currentTime -q`;
currentUnit -time $timeFormat;

Comments

You cannot use multi-line /* */ comments in expressions. You can use // comments.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License