To understand expressions better, try the following simple exercises. Once you’re comfortable with the process and how to use the expression editor, you can go on to do more complicated expressions and setups, as described in Expression Examples.
Setting Up a Constant Expression
1. Get a primitive sphere (keep it simple!).
2. Select the sphere and press Ctrl+k (this opens the sphere’s Local Transform property editor).
3. Right-click the animation icon (green box) of the local Position Y parameter and choose Set Expression.
4. In the expression editor, enter the value of 5 in the expression pane and click the Apply button, but keep the expression editor open to take a peek at what you just did:
- At the top of the expression editor is the parameter (sphere.kine.local.posy) that you’ve set to be equal to 5.
- Notice that the Position Y animation icon has the letter “C” in it to indicate that it’s a constant expression (where the value is a number).
- An Expression page is added to the Local Transform property editor so that you can easily edit this expression later, including adding comments.
5. Close the expression editor.
Congratulations, you’ve just set the simplest kind of expression! The sphere is now fixed at 5 units on its Y axis. You won’t be able to translate it anywhere else in this direction, but you can still move it in X and Z.
Trying it another way
Here’s another way of creating a constant expression:
1. Get another primitive sphere and set its Translation Y value to 5.
2. Press Ctrl+k, right-click the Position Y parameter’s animation icon, and choose Set Expression.
Notice the expression editor opens with the value of 5 already in it. You’ve just created a constant expression the same as in the first exercise.
Creating a Simple Equivalency Expression
You can also easily create simple A = B expressions between parameters:
1. Open a new scene and get a primitive sphere and a null.
2. Translate the null in X a little to offset it from the origin and the sphere.
3. Select the sphere and press Ctrl+k to open its Local Transform property editor. Lock this property editor to keep it open (click its keyhole icon).
4. Select the null and press Ctrl+k to open a Local Transform property editor for it.
5. Drag and drop the animation icon for the null’s Position X parameter to the sphere’s Position X parameter in the other property editor.
- The expression editor opens with the affected parameter is sphere.kine.local.posx. Its expression below is null.kine.local.posx, which means that the sphere takes its posx value from the null’s posx value.
- The sphere’s animation icon for the Position X parameter now has an equal sign (=) in it to indicate the expression.
|
If there was animation on the icon being dragged, the animation would have been copied to the other parameter, but no expression would have been set. |
6. Test the expression by translating the null in X: the sphere should follow in X.
7. Close the expression editor and the two property editors to keep the scene uncluttered.
Trying it another way
Here’s another way to create an equivalency expression:
1. Select the sphere, press Ctrl+k, right-click the animation icon for Position Y, and choose Set Expression.
2. In the expression editor, type null.kine.local.posx in the white expression panel below and click the Apply button.
Now as the null is translated in X, the sphere moves diagonally, getting both its X and Y translation values from the null’s position X value.
To continue with more complex examples, see Expression Examples.
SOFTIMAGE|XSI v.6.01