ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Automating Text Data from External File

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Gordon Grant
Automating Text Data from External File
on May 7, 2020 at 7:15:50 pm
Last Edited By Gordon Grant on May 7, 2020 at 7:47:25 pm

I want to automate the display of external text in a movie at specific times.

The text file will contain 1 field with multiple values ie Black, Red, Blue, Green. There will be 50 values in the actual text file.

I am happy to format the text file into whichever format is best for a script to access.

The movie will show each value at 5 second intervals in the same text box (ie in the same location and style in the movie).

The intended result is to have a text box that shows the values Black, Red, Blue, Green in sequence like this:

0s-5s : Black
5s-10s : <>
10s-15s : Red
15s-20s : <>
20s-25s : Blue
25s-30s : <>
30s-35s : Green

I have lots of movies to render in this style, so I am hoping that it will be possible to use a script so that I don't have to manually type in 50 new values for each movie.

I am guessing that I should read the external text file values into an array and then reference the array elements in the script?

Would someone be able to point me in the right direction please? I am using AE 2020. Thanks!

My current script (where I have to manually update each data value) is this:

if (time>0 && time&lt;5) "Black"
else if (time>5 && time &lt; 10) ""
else if (time>10 && time &lt; 15) "Red"
else if (time>15 && time &lt; 20) ""
else if (time>20 && time &lt; 25) "Blue"
else if (time>25 && time &lt; 30) ""
else if (time>30 && time &lt; 35) "Yellow"
else if (time>35 && time &lt; 40) ""
else if (time>40 && time &lt; 45) "Green"
else ""


Return to posts index

Andrei Popa
Re: Automating Text Data from External File
on May 7, 2020 at 7:51:19 pm

Make a file with each value on a single row. If the layer must be empty, leave a blank row.

EG:
Red

Blue

Yellow

Make a text layer. Select it and then run this script:

var myTextProp = app.project.activeItem.selectedLayers[0]("ADBE Text Properties")("ADBE Text Document");
var myFile = File.openDialog("Select your source file");
if(myFile != null&&myFile.open("r")){
var myString = myFile.read();
myFile.close();
}

var arrayOfWords = myString.split('\n');

for(var i = 0; i < arrayOfWords.length;i++){
myTextProp.setValueAtTime(5*i,arrayOfWords[i])
}


Andrei
My Envato portfolio.


Return to posts index

Gordon Grant
Re: Automating Text Data from External File
on May 7, 2020 at 7:56:32 pm

Andrei

I really appreciate you taking the time and your fast response! Could you explain how I run the script please? I know how to add it to the Source Text of the text layer but that generates an error - so I am obviously not executing the script correctly.

Thanks!


Return to posts index


Gordon Grant
Re: Automating Text Data from External File
on May 7, 2020 at 8:02:50 pm

I found it!

I have saved the script as a .JS file and then used FILE>SCRIPTS>RUN SCRIPT FILE

Thank you very much!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]