Activity › Forums › Adobe After Effects › Importing a .txt file to use as source text, but without lists/arrays/etc formatting.
-
Importing a .txt file to use as source text, but without lists/arrays/etc formatting.
Posted by James Houston on February 4, 2014 at 1:40 amHello,
I have hundreds of sequential text files each containing a few sentences.
I’d like to flash the contents of each text file onscreen in sequence.Is there a way of telling an AE text layer to read & display ALL of the contents in a specific .txt file? All the tutorials/advice I can find on Google state that I’d need to have my original data in an array format first.
thanks.
jamesJames Houston replied 12 years, 3 months ago 2 Members · 3 Replies -
3 Replies
-
Declan Smith
February 4, 2014 at 12:35 pmNot easily, but yes, there is always a way. evalFile will ‘evaluate’ an external script, that’s it, that’s all it does. In this, it will of coarse evaluate variables, so as long as your text conforms to these requirements, then it will work.
For example, supposing your text file contained the following:
——–
Here is “my text” and [not] someone else’s!!Oh and here is another line of my fine work
——–The using $.evalFile(‘/somepath/somefile’) on it’s own will (as you have found) not work.
BUT
If your file read like this:
——–
contents=[“\
Here is \”my text\” and \[not\] someone else’s!!\
\
Oh and here is another line of my fine work\
“]
——–Then the text expression below would indeed display the contents of the file:
try {
$.evalFile(“/Volumes/Media/Projects/AE/keys2.txt”);
eval(“contents”)[0];
} catch (err) {
“Error”;
}So, what you need to do, outside of AE, is pre-process your text files. This can be done very simply with a script (depending on what platform you are on, Mac or Windows). The requirements are as follows (in this order):
1. Replace \ with \\
2. Replace [ with \[
3. Replace ] with \]
4. Replace ” with \”
5. Insert a line at the beginning
contents=”[
6. Insert \ at the end of every line
7. Append the following line to the end of the file
]”[EDIT} a simple perl script to do this as follows (I assume entirely that you are on a Mac so you would do all this in a terminal window)
—–
#!/usr/bin/perlprint ‘contents=[“‘;
while (
) {
chomp;
s//\/g;
s/[/[/g;
s/]/]/g;
s/”/”/g;
print $_ . “n”;
}
print ‘”]’.”n”;
—–to use, save the file as “txt2ae.pl” then
cat source.txt | perl -f txt2ae.pl > dest.txt
If you have loads of files, then wrap it in a script. For example, if all your files that you need in AE have the .txt extension:
for file in `ls *.txt | grep -v AESRC_`; do cat ${file} | perl -f makeae.pl > AESRC_${file}; done
This will create converted versions of your files that will have their filename starting with AESRC_
If you go down this route then I would further advise that you rename your files to contain the layer name or comp name, so that you can duplicate the layers easily within AE.
Declan Smith
https://www.madpanic.tv
After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase“it’s either binary or it’s not”
-
Declan Smith
February 4, 2014 at 5:37 pmHere is a project and all the scripts and example text files that should show how this works.
Declan Smith
https://www.madpanic.tv
After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase“it’s either binary or it’s not”
Reply to this Discussion! Login or Sign Up