Using Expressions


Expressions are MEL scripts that control keyable attributes and are executed at every frame. They're used in animation to set attribute values, based either on the current time or on other attributes that are animated directly.

You can create, view, and edit expressions in the Expression Editor. It displays a list of expressions in the Selection area, and selecting one of these expressions displays it in the Expression text box for editing. When no expression is selected, you can use the Expression text box to create a new one.

You can also create an expression for an attribute in the Attribute Editor.

To create an expression:

1.

Select an object, and press to open the Attribute Editor.

2.

In the Transform Attributes section, in the field for the attribute that you want the expression to control, type an equal sign (=) followed by the MEL script that will determine the attribute's value. For example, enter =sin(time) in the middle Translate field.

The field turns purple, indicating that it is controlled by an expression (Figure 17.32).

Figure 17.32. Entering an expression in an attribute's field turns the field purple.


3.

Click Play to see the effect of the expression.

The sphere moves up and down as determined by the value of the sin(time) function, which is based on a sine wave (Figure 17.33).

Figure 17.33. When you click Play, the sphere moves up and down.


Tips

  • The time keyword used in this task is a variable that's only accessible from an expression, not in ordinary MEL scripts. It provides the current time in seconds and fractions of a second. You can also use the frame keyword in an expression to get the current frame number.


To edit an expression:

1.

Create an expression by following the steps in the previous task.

2.

Right-click the purple field, and select Edit Expression from the pull-down menu that appears (Figure 17.34).

Figure 17.34. You can right-click a field that's controlled by an attribute to access a pull-down menu of relevant options.


The Expression Editor opens with the object and attribute selected (Figure 17.35).

Figure 17.35. Choosing Edit Expression from the attribute's pull-down menu opens the Expression Editor.


3.

Edit the MEL script in the Expression text box. For example, replace sin(time) with sin(time*10).

4.

Click Edit to save the changes.

5.

Click Play to view the modified effect of the expression.

The object now moves much faster.




Maya 7 for Windows and Macintosh(c) Visual Quickstart Guide
Maya 7 for Windows & Macintosh
ISBN: 0321348990
EAN: 2147483647
Year: 2006
Pages: 185

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net