In the following steps, you create a default sphere and write an expression to increase its Scale Y attribute as the animation time increases during playback.
If you write several expressions in the same scene, giving each a name might make it easier to find the desired expression if you decide to alter it later. If you don’t provide a name, the expression receives a default name, for instance, expression1.
Note that the Attributes list displays Ball’s keyable, unlocked attributes—the attributes you’ll most likely want to animate with an expression. Use the scroll bar to see the entire list.
Type all characters exactly as shown above. Entries are case sensitive. The semicolon (;) signifies the end of the expression statement. End each statement in an expression with a semicolon.
An error message appears in the Script Editor and Command Line’s response area if the expression has incorrect syntax or typing mistakes.
Creating the expression checks it for syntax errors and converts it to a form Maya can execute when you return to the start time or play the animation. Clicking Create also executes the expression for the current frame.
The expression sets Ball’s scaleY attribute to the value of time + 1. Ball.scaleY is the full name of the attribute. A period separates the name of the object and attribute. Note that you must spell the object and attribute with uppercase and lowercase letters as they appear in the Expression Editor’s Objects and Attributes lists.
The word time is a commonly used predefined variable that updates as an animation plays. It contains the elapsed number of seconds from the first frame to the current frame. The value increases with the increasing frame number.
At the default animation playback rate of 24 frames per second, time has these values (rounded to four decimal places):
You can find the time elapsed in the animation at any frame by calculating this formula with a desktop calculator:
For example, if the frame rate is 24 frames/second and the animation is at frame 1, the elapsed time is 1 divided by 24, or 0.0417. At frame 6, the elapsed time is 6 divided by 24, which equals 0.25. Note that if your frame rate was 30 frames/second the calculated values would be different.
Frame | Time (seconds) | Ball.scaleY (time + 1) |
---|---|---|
0 |
0 |
1 |
1 |
0.0417 |
1.0417 |
2 |
0.0833 |
1.0833 |
3 |
0.125 |
1.125 |
24 |
1.0 |
2.0 |
240 |
10.0 |
11.0 |
Maya executes the expression each frame. This causes the object size to scale along its Y-axis, stretching its height during playback.
To see the value of Ball’s scaleY attribute at any particular frame, select Ball, display the Channel Box, and stop the animation at the desired frame. The Channel Box updates its values after you stop the animation.
The scaling is smooth because the geometry stretches in synch with the small time increments of the animation playback.