← Back to blog
|
July 6, 2023

How to write After Effects expressions for ExtendScript

Writing After Effects scripts has many quirks. One of them is applying expressions to properties.

While ExtendScript relies on ES3 JavaScript, expressions can be written in modern JavaScript. But since expressions are not executed at the script level, you need to pass them along as a string.

After Effects expression in ExtendScript

This is easy enough if the expression is a single line, but if you want to include line breaks and indentations, a lot more formatting is required.

My go-to method is wrapping each line in single quotes, then adding a line break at the end of each line. This is rather tedious and makes revisions much harder since you lose all the syntax highlighting.

Multi line After Effects expression in ExtendScript

To keep my code more organized, I keep all the expressions I am using for a given script within their own module pattern.

That’s why I created Expressify. This is an open source tool that compiles After Effects expressions into formatted JavaScript strings automatically.

With Expressify you can write each expression in modern JavaScript (or just copy and paste from After Effects) then save it as its own js file. Once a file is added to the designated source folder, Expressify will automatically convert the expression into a string and add it to a module pattern called ExpressionLib.js.

Multiline After Effects expression
After Effects expression formatted with Expressify

With an include statement you can reference all the expressions within the ExpressionLib.js file.

You never have to worry about the ExpressionLib.js file itself. Any time you add, delete, or edit the expression files in your source folder, Expressify will update ExpressionLib.js automatically.

Expressify makes it way easier to write and manage expressions in your After Effects scripts.

Download Expressify for free.

Get more After Effects tricks in your inbox.

Check your inbox.

Please confirm your email, so we can keep you in the loop.
Oops! Something went wrong while submitting the form.