AfterEffects

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, such as Notepad, Simple Text, or even Stickies. However, because expressions are written in relation to other layers in a project and may use specific layer names, it doesn’t always work to simply transfer expressions between projects.

If you want to save an expression for use in another project, you should add comments to the 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 will contain the expression along with all keyframe values.

You can copy an expression from a layer property, with or without the property’s keyframes. Copying an expression without keyframes is particularly 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.

  • 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, choose Edit > Copy Expression Only, select the target properties, and paste.
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 yourself if you are pasting an expression from a Position property into a Scale property.