Expressions

Expression is a mathematical description that controls a channel. You cannot use keys and expression together in the same channel in Maya.

Example:

Create a sphere and rename it "ball".
Open Expression Editor by selecting Window -> Animation Editors -> Expression Editor...
In Expression Editor, select the object "ball" and the attribute "translateY", for which you will be creating expressions in the following examples.
You will type in expressions in the box under "Expression".

For instance, type in
ball.traslateY = sin(frame);

Click on "Create". Play the animation.
To see the channel as a graph, in Graph Editor, select View -> Show results.

Change the expression to:
ball.translateY = cos(frame);
Click on "Edit".
Notice that the curve now starts with the parameter value 1.0, instead of 0.0 in the first frame.

Try the followings:
ball.translateY = cos(frame/10);
ball.translateY = abs(cos(frame/10));
ball.translateY = 10*abs(cos(frame/10));

You can use "if...else" in an expression. For instance,
if (ball.translateY<1.0)
ball.scaleX=1.5;
else
ball.scaleX=1;

Replace the above four lines with the following for the x-, y-, and z- scaling (squash):
if (ball.translateY<1.0) {
ball.scaleX=1.5;
ball.scaleY=0.5;
ball.scaleZ=1.5;

} else {
ball.scaleX=1.0;

ball.scaleY=1.0;
ball.scaleZ=1.0;
}

Note: To add a user defined channel, select Modify -> Add Attribute...

For instance, add a user defined channel and name it "user1".

Create the following expression for user1:
ball.user1=(400-frame)/40;

Modify the expression for translateY as follows:
ball.translateY = ball.user1*abs(cos(frame/10));

The bounce height gradually decreases from frame 0 to frame 400.