Using data from an external file to drive expressions in AE

If you want your AE project to access data from an external file to drive expressions you can use the javascript evalFile() function in an expression.

—This post is kinda outdated. In recent versions After Effects has improved its support for data driven animation. The methods here are still valid, but you don’t need to jump through as many hoops.—

Given a data file called test.js saved on your Desktop, you can access the file thus: evalFile("~/Desktop/test.js") (this works on windows and mac, mercifully AE uses URIs rather as well as the native file paths so it will accept  ~/, the shortcut to your home directory, and accepts forward slashes instead of backslashes, so you don’t have to escape everything).

If the file contains something like this:

var vals = {"rotation":8, "scaleX":150, "scaleY":200};

you can use this expression, e.g. in the scale property:

[eval(vals).scaleX, eval(vals).scaleY]

the first line reads the file and treats it as source for the expression, so vals is defined as an object with rotation, scaleX and scaleY properties, which we access as the value for our scale property.

You can also use things like and in the eval function, so that one data file can feed multiple comps and layers, e.g.:

Data file:

var comp1Lyr1 = {"rotation":8, "scaleX":150, "scaleY":200};
var comp2Lyr1 = {"rotation":98, "scaleX":10, "scaleY":20};
var comp2Lyr2 = {"rotation":0, "scaleX":10, "scaleY":100};


And this Expression, on a layer called “Lyr1” in a comp called “comp1”:

var theID = +;
[eval(theID).scaleX, eval(theID).scaleY]

The problem about using external source files is that the path is brittle—move or rename the data file and it won’t work.

It also gets read off the disk every time the frame is rendered – which can be dozens of times per frame if you’re using motion blur. You might be better off using a script to import the data once and turn it into values or expressions.

Another method is to use a text layer as your expression source. I think I invented this, I haven’t been able to find anyone else who has published the method. Details here

If you want something that can chomp a CSV file and turn it into mograph sparklyness then you’ll probably want to do it with extendscript. There are frameworks for doing this, like dataclay: This is a pretty pricey option, the alternative is to hire someone who knows extendscript; hit me up if you want my rates and availability.

One comment

  1. How we can hit you up for your rates and availability? ;p


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.