Sidenote: There are of course plugins available that pull in data from spreadsheets and export out numerous animations with ease. They can be great if you’re working on some complex localisations with a number of different dynamic elements, perhaps also imagery and video that changes. In my case, I just wanted something simple: an expression pulling in data from a text file.
Step 1: Create your text file containing copy variants.
Create a new .txt document using your text editor of choice - TextEdit (mac) or NotePad (pc) are good options.
We will then add our copy variants, each one on a new line, following the below format
Here’s an example of how your text file will look once it is populated with data:
Once you’re happy, save the .txt file and make a note of the file path as well as the name of the text file. You will need this when creating your After Effects expression. In this example, I named my file data.txt and saved it to the desktop.
Step 2: Create your text field
Head over to After Effects, and in your desired comp, create a text field. (Select Text tool, click and drag out a bounding box to the desired size) Here’s how mine looks below:
Note that I created a separate text field for the dynamic copy in this instance as the copy before that doesn’t change. You could alternatively make the whole text field dynamic and input the full copy line in to your txt file if needed.
Step 3: Expression time!
In After Effects, the expression is always applied to a property, so in this instance, we will apply our expression to the ‘Source Text’ property on the text layer. In order to set an expression, alt+click the timer icon next to Source Text, and an input field will appear where the expression can be pasted in. Below is the expression that we will paste in:
try{
myPath = "~Desktop/data.txt";
$.evalFile(myPath);
eval(thisComp.name)[0];
}catch(err){
"MISSING";
}
So long as the path to your txt file is correct, and the name of your comp matches the var in your data.txt file, your text should match the text in the data.txt file. That was easy right?
Step 4: Now for the fun part!
Did you notice how the variables in the data.txt file are numbered sequentially? This will come in handy now.
Go to your project panel in After Effects and select your master comp (in my case that is: LocalisableComp_01). Now hit cmd+D. After Effects will duplicate the comp, incrementing the numbered suffix each time, which matches our data.txt var name perfectly! Once you have duplicated your comp as many times as needed, open up the new comps and check the dynamic copy should be different in each comp. You should be good to go!
Summary
Expressions can make your life so much easier, they needn’t be intimidating, and there are plenty of resources available online to help you figure out what to do. Have a play around and see what you can achieve with them.