|
|
Add, edit, and remove expressionsYou can enter entire expressions yourself, by manually typing them or by using the Expression Language menu; or you can create an expression with the pick whip or paste it from an example or other property. You can do all of your work with expressions in the Timeline panel, though it is sometimes more convenient to drag the pick whip to a property in the Effect Controls panel. You enter and edit expressions in the expression field, a resizable text field in the time graph. The expression field appears alongside the property in layer bar mode; the expression field appears at the bottom of the Graph Editor in Graph Editor mode. You can write an expression in a text editor and then copy it into the expression field. When you add an expression to a layer property, a default expression appears in the expression field. The default expression essentially does nothing—it sets the property value to itself, which makes tweaking the expression yourself easy. ![]() Expression interface in the Timeline panel in layer bar mode
While you are editing an expression, previews of all kinds are suspended; a red bar appears at the bottom of panels that are waiting for you to exit text-editing mode. The values for a property that contains an expression appear in red or pink type. A good way to begin working with expressions is to create a simple expression with the pick whip and then adjust the behavior of the expression using simple math operations, such as those listed in the following table:
For example, you can double the result by typing *2 at the end of the expression; or you can halve the result by typing /2 at the end of the expression. As you develop comfort editing expressions, you can combine these simple operations—and more. For example, you can add /360*100 to the end of an expression to change its range from 0-360 to 0-100. This change would be useful if you wanted to convert the values of a 360-degree dial to a slider that is measured in percentages. The Expression Language menu in the Timeline panel contains language elements specific to After Effects that you can use in an expression. This menu is helpful for determining valid elements and their correct syntax; use it as a reference for available elements. When you choose any object, attribute, or method from the menu, After Effects automatically inserts it in the expression field at the insertion point. If text is selected in the expression field, the new expression text replaces the selected text. If the insertion point is not in the expression field, the new expression text replaces all text in the field. The Expression Language menu lists
arguments and default values. This convention makes it easy to remember
which elements you can control when you write an expression. For
example, in the language menu, the wiggle method in the Property
category appears as wiggle(freq, amp, octaves=1, amp_mult=.5, t=time).
Five arguments are listed in the parentheses following wiggle.
The = in the last three arguments indicates that
using those arguments is optional. If you specify no values for
them, they default to 1, .5, and the current time, respectively.
Important: You must replace the argument names written
by the Expression Language menu with actual values.
Paul Tuersley provides a script on the AE Enhancers forum that automatically adds wiggle, smooth, and loop expressions to selected properties. Using this script is a good way for a beginner to experiment with expressions. Jeff Almasol provides a script that automatically processes expressions, making specified changes. For example, the script can be used to automatically remove or enable disabled expressions. For more information, see Jeff Almasol’s redefinery website. Add, disable, or remove an expression
Edit an expression with the pick whipIf you are not familiar
with JavaScript or the After Effects expression language, you can
still take advantage of the power of expressions by using the pick
whip. You simply drag the pick whip ![]() Drag the pick whip to a property to create a link to the value
of the property. You can drag the pick whip to the name or value of a property. If you drag to the name of a property, the resulting expression displays all the values as one. For example, if you drag the pick whip to the name of the Position property, an expression like the following appears: thisComp.layer("Layer 1").transform.position
If you drag the pick whip to one of the component values of the Position property (such as the y value), an expression like the following appears, in which both the x and y coordinates of the property are linked to the y value of the Position property: temp = thisComp.layer("Layer 1").transform.position[1];
[temp, temp]
If the layer, mask, or effect that you drag the pick whip to does not have a unique name in its local context, After Effects renames it. For example, if you have two or more masks named “Mask” on the same layer, and you drag the pick whip to one of them, After Effects renames it “Mask 2”. The format of expressions created by the pick whip is determined by the Expression Pick Whip Writes Compact English preference (Edit > Preferences > General (Windows) or After Effects > Preferences > General (Mac OS)). By default, the pick whip creates compact English expressions, which use the names for properties as they appear in the Timeline panel for the properties within an expression. Because these names are coded into the application and never change, these expressions can work when After Effects is running in another language. Any property names that you can change are enclosed in double quotation marks and remain the same in any language. If you don’t plan on sharing your projects across languages, you can deselect this preference. This preference does not affect effect names or effect properties. Here is an example in compact English: thisComp.layer("Layer 1").transform.position
Here is the same expression, not in compact English: thisComp.layer("Layer 1")("Transform")("Position")
Note: Because
the default is to use compact English, this document uses compact English
in most examples and illustrations.
Note: If you use the pick whip to create an expression to
refer to a layer, and that layer has the same name as another layer
in the same composition, then the targeted layer’s name changes.
The new layer name is the old layer name with a numeral at the end.
This change is necessary to ensure that the expression unambiguously
refers to a single layer in the composition.
|