User Guide Cancel

Editing expressions

  1. After Effects User Guide
  2. Beta releases
    1. Beta Program Overview
    2. After Effects Beta Home
  3. Getting started
    1. Get started with After Effects
    2. What's new in After Effects 
    3. Release Notes | After Effects
    4. After Effects system requirements
    5. Keyboard shortcuts in After Effects
    6. Supported File formats | After Effects
    7. Hardware recommendations
    8. After Effects for Apple silicon
    9. Planning and setup
  4. Workspaces
    1. General user interface items
    2. Get to know After Effects interface
    3. Workflows
    4. Workspaces, panels, and viewers
  5. Projects and compositions
    1. Projects
    2. Composition basics
    3. Precomposing, nesting, and pre-rendering
    4. View detailed performance information with the Composition Profiler
    5. CINEMA 4D Composition Renderer
  6. Importing footage
    1. Preparing and importing still images
    2. Importing from After Effects and Adobe Premiere Pro
    3. Importing and interpreting video and audio
    4. Preparing and importing 3D image files
    5. Importing and interpreting footage items
    6. Working with footage items
    7. Detect edit points using Scene Edit Detection
    8. XMP metadata
  7. Text and Graphics
    1. Text
      1. Formatting characters and the Character panel
      2. Text effects
      3. Creating and editing text layers
      4. Formatting paragraphs and the Paragraph panel
      5. Extruding text and shape layers
      6. Animating text
      7. Examples and resources for text animation
      8. Live Text Templates
    2. Motion Graphics
      1. Work with Motion Graphics templates in After Effects
      2. Use expressions to create drop-down lists in Motion Graphics templates
      3. Work with Essential Properties to create Motion Graphics templates
      4. Replace images and videos in Motion Graphics templates and Essential Properties
      5. Animate faster and easier using the Properties panel
  8. Drawing, Painting, and Paths
    1. Overview of shape layers, paths, and vector graphics
    2. Paint tools: Brush, Clone Stamp, and Eraser
    3. Taper shape strokes
    4. Shape attributes, paint operations, and path operations for shape layers
    5. Use Offset Paths shape effect to alter shapes
    6. Creating shapes
    7. Create masks
    8. Remove objects from your videos with the Content-Aware Fill panel
    9. Roto Brush and Refine Matte
  9. Layers, Markers, and Camera
    1. Selecting and arranging layers
    2. Blending modes and layer styles
    3. 3D layers
    4. Layer properties
    5. Creating layers
    6. Managing layers
    7. Layer markers and composition markers
    8. Cameras, lights, and points of interest
  10. Animation, Keyframes, Motion Tracking, and Keying
    1. Animation
      1. Animation basics
      2. Animating with Puppet tools
      3. Managing and animating shape paths and masks
      4. Animating Sketch and Capture shapes using After Effects
      5. Assorted animation tools
      6. Work with Data-driven animation
    2. Keyframe
      1. Keyframe interpolation
      2. Setting, selecting, and deleting keyframes
      3. Editing, moving, and copying keyframes
    3. Motion tracking
      1. Tracking and stabilizing motion
      2. Face Tracking
      3. Mask Tracking
      4. Mask Reference
      5. Speed
      6. Time-stretching and time-remapping
      7. Timecode and time display units
    4. Keying
      1. Keying
      2. Keying effects
  11. Transparency and Compositing
    1. Compositing and transparency overview and resources
    2. Alpha channels and masks
    3. Track Mattes and Traveling Mattes
  12. Adjusting color
    1. Color basics
    2. Color management
    3. Color Correction effects
    4. OpenColorIO and ACES color management
  13. Effects and Animation Presets
    1. Effects and animation presets overview
    2. Effect list
    3. Effect Manager
    4. Simulation effects
    5. Stylize effects
    6. Audio effects
    7. Distort effects
    8. Perspective effects
    9. Channel effects
    10. Generate effects
    11. Time effects
    12. Transition effects
    13. The Rolling Shutter Repair effect
    14. Blur and Sharpen effects
    15. 3D Channel effects
    16. Utility effects
    17. Matte effects
    18. Noise and Grain effects
    19. Detail-preserving Upscale effect
    20. Obsolete effects
  14. Expressions and Automation
    1. Expressions
      1. Expression basics
      2. Understanding the expression language
      3. Using expression controls
      4. Syntax differences between the JavaScript and Legacy ExtendScript expression engines
      5. Editing expressions
      6. Expression errors
      7. Using the Expressions editor
      8. Use expressions to edit and access text properties
      9. Expression language reference
      10. Expression examples
    2. Automation
      1. Automation
      2. Scripts
  15. Immersive video, VR, and 3D
    1. Construct VR environments in After Effects
    2. Apply immersive video effects
    3. Compositing tools for VR/360 videos
    4. Advanced 3D Renderer
    5. Import and add 3D models to your composition
    6. Import 3D models from Creative Cloud Libraries
    7. Image-Based Lighting
    8. Extract and animate lights and cameras from 3D models
    9. Tracking 3D camera movement
    10. Cast and accept shadows
    11. Embedded 3D model animations
    12. Shadow Catcher
    13. 3D depth data extraction
    14. Modify materials properties of a 3D layer
    15. Work in 3D Design Space
    16. 3D Transform Gizmos
    17. Do more with 3D animation
    18. Preview changes to 3D designs real time with the Mercury 3D engine
    19. Add responsive design to your graphics 
  16. Views and Previews
    1. Previewing
    2. Video preview with Mercury Transmit
    3. Modifying and using views
  17. Rendering and Exporting
    1. Basics of rendering and exporting
    2. H.264 Encoding in After Effects
    3. Export an After Effects project as an Adobe Premiere Pro project
    4. Converting movies
    5. Multi-frame rendering
    6. Automated rendering and network rendering
    7. Rendering and exporting still images and still-image sequences
    8. Using the GoPro CineForm codec in After Effects
  18. Working with other applications
    1. Dynamic Link and After Effects
    2. Working with After Effects and other applications
      1. Export After Effects project as Premiere Pro project
    3. Sync Settings in After Effects
    4. Creative Cloud Libraries in After Effects
    5. Plug-ins
    6. Cinema 4D and Cineware
  19. Collaboration: Frame.io, and Team Projects
    1. Collaboration in Premiere Pro and After Effects
    2. Frame.io
      1. Install and activate Frame.io
      2. Use Frame.io with Premiere Pro and After Effects
      3. Frequently asked questions
    3. Team Projects
      1. Get Started with Team Projects
      2. Create a Team Project
      3. Collaborate with Team Projects
  20. Memory, storage, performance
    1. Memory and storage
    2. How After Effects handles low memory issues while previewing    
    3. Improve performance
    4. Preferences
    5. GPU and GPU driver requirements for After Effects
  21. Knowledge Base
    1. Known issues
    2. Fixed issues
    3. Frequently asked questions
    4. After Effects and macOS Ventura
    5. How After Effects handles low memory issues while previewing

Learn how to add, edit, and work with expressions in After Effects.

Add or remove an expression from a property

Any property that you can keyframe can use an expression.

To add and reveal an expression, select the property in the Timeline panel and do one of the following:

  • Select Animation > Add Expression. To remove, select Animation > Remove Expression.
  • Press Alt+click (Windows) or Option+click (macOS) the stopwatch button next to the property name in the Timeline panel or the Effect Controls panel. Repeat this step to remove the expression.

When the expression is activated, four icons appear under the property, and the value turns red.

The pick whip is the drag-and-drop selection tool for linking in After Effects. Select and hold the spiral icon next to the expression to enter selection mode. A whip links to your cursor as you drag to another property. Releasing the click targets the property underneath, generating expression syntax automatically.

expression selection

To link a set of properties across layers and compositions, use property links:

  1. Select any one property or set of properties and choose Edit > Copy With Property Links or Edit > Copy With Relative Property Links.

  2. Then paste those properties on any layer in a composition. The pasted properties will now be connected to the layer from which the properties were copied. Any change made to the original property is reflected in the instances of the pasted property links.

    (or)

    You can also copy an entire layer with property links and paste it to create duplicates that follow the changes made to the original.

The result of copying a layer’s Position property with the Copy With Relative Property Links command is as follows:

thisComp.layer("control_layer").transform.position

The result of copying a layer’s Position property with the Copy With Property Links command is as follows:

comp("source_comp").layer("control_layer").transform.position

Disable expressions

To temporarily disable an expression, select the Enable Expression switch. When an expression is disabled, a slash appears through the switch.

expression

Edit expressions

Edit an expression with the pick whip

If you're unsure about using JavaScript or After Effects expressions, go ahead and use the pick whip tool to get started. This tool is an easy way to link properties of expressions. 

text

  1. Make sure your property has an expression applied to it. For example, Alt+Click (Windows) or Opt+Click (macOS) the stopwatch icon to the left of the Scale property to apply an expression.

  2. Go to the Timeline panel and select inside the text field to activate the Expression Editor. Place the cursor where you want to edit the expression.

  3. The expression is entered 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 isn't in the expression field, the new expression text replaces all text in the field.
  4. 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
  5. 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. 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]
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.

Format of expressions created by the pick whip

The format of expressions created by the pick whip is determined by the Expression pick whip writes compact English preference.

  • Edit > Preferences > General (Windows)
  • Preferences > Scripting & Expressions (macOS)

The pick whip creates expressions, which use the names for properties as they appear in the Timeline panel. As these names are in-built, they can work when After Effects is running in another language. Editable property names are enclosed in double quotation marks and remain the same across languages. Deselect this option if the project isn't being shared in other languages.

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.

Edit an expression manually

Edit an expression manually

  1. Enter text-editing mode by clicking in the expression field. When you enter text-editing mode, the entire expression is selected. To add to the expression, click within the expression to place the insertion point; otherwise, you will replace the entire expression.

  2. Type and edit text in the expression field, optionally using the Expression Language menu. To see more of a multiline expression, drag the bottom or top of the expression field to resize it.

  3. To exit text-editing mode and activate the expression, do one of the following:
    • Press Enter on the numeric keypad.
    • Click outside the expression field.

Show expressions and the expression graph

Showing expressions in the Timeline panel

  • Reveal expressions with errors:

You can choose to only show properties which contain expression errors, which helps you quickly view and correct the errors. Use the following steps to do it:

  1. Select the layer(s) you want to view the errors for and right click to open the flyout menu.
  2. Select Reveal > Reveal Expression Errors.
reveal expression error

show expressions

  • Show only properties with expressions:

To show only properties with expressions, select one or more layers and then press EE.

timeline search

  • Timeline search:

Use the search field in the Timeline panel to search expressions as well as other components of a property. If the search string appears in an expression, the property and its containing property groups and layers are shown in the set of search results.

Note:

To resize the expression field, drag its top edge up or down.

Expressions in the Graph Editor

In Graph Editor mode, the single expression field appears as a resizable box at the bottom of the Graph Editor. It shows only the expression for the selected property. To show multiple expression fields simultaneously, the Timeline panel must be in layer bar mode.

text

To toggle between layer bar mode and Graph Editor mode, press Shift+F3. You can also use the Graph Editor   button at the top of the Timeline panel for this. 

text

To show the expression field in the Graph Editor, choose Show Expression Editor from the Choose graph type and options menu at the bottom of the Graph Editor. When you add an expression to a property, the expression editor is shown.

text

To see how an expression changes the value or velocity graph, select the Show Post-Expression Graph button while showing the value or velocity graph in the Graph Editor.

Read the graph editor

The dimly colored graph displays the value or velocity before the expression is applied. The brightly colored graph displays the value or velocity after the expression is applied. Turning on the graph overlay for the Position property changes the motion path display in the Composition panel so you can see the expression-affected path.

Display colors in a graph (gif)

Add comments to an expression

If you write a complex expression, you should add comments that explain what the expression does and how its pieces work.

Use one of the following syntaxes to comment your code:

  • Type // at the beginning of the comment. Any text between // and the end of the line is ignored.
    For example: //This is a comment.
  • Type /* at the beginning of the comment and */ at the end of the comment. Any text between /* and */ is ignored.
    For example: /*This is a multiline comment.*/

Save and reuse expressions

Once you have written an expression, you can save it for future use by copying and pasting it into a text-editing application. You can also save it in an animation preset or template project. However, because expressions are written in relation to other layers in a project and may use specific layer names, you must sometimes modify an expression to transfer it between projects.

You can define your own functions within expressions using normal JavaScript function syntax. In this example, a function is defined that calculates the average of two values, and the last line uses this function:

  function average(a, b) 
  { 
    return (a + b) / 2; 
  } 
  average(position, thisComp.layer(1).position);
Note:

You must define each function fully within each expression in which it is used. There is no global library of functions that you can add to.

If you want to save an expression for use in another project, consider adding comments to the expression. (See Add comments to an expression.) You should also use variables so that you can change a value in one place rather than having to change it in several places.

For example, this expression has a multiline comment at the beginning that explains what the expression does and a short comment after a variable is declared and initialized that tells what the variable is for:

  /*  This expression on a Source Text property reports the name 
      of a layer and the value of its Opacity property. */  
    
  var myLayerIndex = 1; // layer to inspect, initialized to 1, for top layer  
    
  thisComp.layer(myLayerIndex).name + ": \rOpacity = " +   thisComp.layer(myLayerIndex).opacity.value

You can save an animation preset that includes an expression and reuse it in other projects, as long as the expression does not refer to properties that don’t exist in the other projects. When you save a preset in which a property has an expression but no keyframes, only the expression is saved. If the property has one or more keyframes, the saved preset contains the expression along with all keyframe values.

Save an expression as a preset

You can save an expression as a preset and use it in other projects using the following steps:

  1. In the TImeline, select the property on which the expression is applied, for example - the expression is applied to the Rotation property of a layer, so select it. Then, select Animation > Save Animation Preset.

  2. Rename the preset - let's say "Time40", and save. By default, it's saved in the User Presets folder as an Adobe After Effects Preset file.

  3. To apply your preset, twirl open Animation Presets under the Effects & Controls menu. You have two folders there - Presets and User Presets, twirl open User Presets. It has all the presets that you create within After Effects. Drag the "Time40" preset onto the layer you are working on and the expression is applied!

Copy an expression from a layer property

You can copy an expression from a layer property, with or without the keyframes for the property.

  • To copy an expression and keyframes from one property to other properties, select the source layer property in the Timeline panel, copy the layer property, select the target layer properties, and paste.
  • To copy an expression from one property to other properties without copying keyframes, select the source property, then select Edit > Copy Expression Only, select the target properties and paste.
Tip:

Copying an expression without keyframes is useful when you want to simultaneously copy multiple expressions and paste them onto one or more new layers or when you want to copy one expression and paste it onto more than one layer.

Note:

As with pasting keyframes and other items, you can often paste the item into the target layer and rely on After Effects to determine which property should be the target of the paste operation. For example, this works for copying Position properties from one layer to another. But you must select the target property if you are pasting an expression from a Position property into a Scale property.

More Expression resources

Now that you have understood some of the concepts behind expressions, come to the community for some real-life examples, and to share your work.

You can also check out Dan Ebberts' excellent collection of example expressions and tutorials on his MotionScript website.

 Adobe

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online