Maya Expressions Part 02 - Conditional Statements


In this second video of my Maya Expressions series, I show how use the graph editor to display a visual representation of the value of our expressions with a graph.

Then I move on to explain the basics of conditional statements in Maya's expression language, which also works with MEL scripts.

A basic conditional statement in MEL and Maya expression language has the structure as such:

if (condition) {
    statement1;
    statement2;

}

Condition is a test to see if a comparison between values is true, or false, for most cases.

Example 1:
if (cube1.translateX > cube2.translateX) { do_something; }

In the above example, if cube1's translateX value is greater than cube2's translateX value, then do_something will be performed.

Example 2:
if (cube1.translateX == cube2.translateX) { do_something; }

In the above, we are testing for equality. if both the values are equal, the do_something will be executed.

Example 3:
if (cube1.scaleX >= cube2.scaleY) { do_something }

In this case, do_something will be executed if cube1.scaleX is equals to cube2.scaleX, or if cube1.scaleX is greater than cube2.scaleX.

The >= or <= comparison operators tests for 2 conditions. In the case of the >= operator, it will test true in the case of "greater than", and also in the case of  "is equals to".

Example 4:
if (cube1.scaleX != cube2.scaleY) { do_something }

In this case, do_something will be performed only if cube1.scaleX is not euqals to cube2.scaleX. The != sign is the comparison operator for inequality.

Comments

Popular posts from this blog

Maya UI Layout Example

Jooble.org - A Jobs Platform for VFX Artists