Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Pulling text from a .txt file

  • Pulling text from a .txt file

    Posted by Chris Street on August 18, 2017 at 6:04 pm

    Hi everyone

    Relatively new to creating expressions After Effects expressions, but not new to After Effects.

    I’ve coded a program that generates a .txt file. I’ve done this because manually typing text between ” and ” is fiddly and annoying in NotePad. The result is something like this (including the spaces between each batch for easier reading:

    IMAGE1 = “Text here”
    DESC1 = “Smaller text here”

    IMAGE2 = “Text here”
    DESC2 = “Smaller text here”

    IMAGE3 = “Text here”
    DESC3 = “Smaller text here”

    and so on, up to “IMAGE20” and “DESC20”.

    The generated document is called “sourcetext.txt” and is saved in the same folder as the After Effects project.

    Within the After Effects project there are 20 compositions containing text. Each one has an expression such as:

    $.evalFile(“\sourcetext.txt”);
    eval(“IMAGE1”);

    which displays the text from the relevant line within the txt document.

    By default, I get an error message that says “Error occurred at line 1. Comp: ‘text_1’, etc.

    Is there anything wrong with what I’m doing? Please help! If it helps, I’m using the CS6 version of AFX.

    IMAGE3 = "Text here"
    DESC3 = "Smaller text here"

    $.evalFile("\sourcetext.txt");
    eval("IMAGE1");

    John Gardner replied 8 years, 2 months ago 4 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 18, 2017 at 11:58 pm

    I’d be surprised if relative addressing works. I tried this with absolute addressing and it works for me:

    $.evalFile(“/c/test/sourcetext.txt”);
    IMAGE1

    (You shouldn’t need that eval() in the last line.)

    Dan

  • Chris Street

    August 19, 2017 at 7:23 pm

    Ah wonderful, so it had to be an absolute path. Many thanks, this aspect works now!

    A slightly different question now (sorry)…

    Within the same text file I would like to reference sizes of rooms/objects in feet and inches. How could I accommodate both single and double quotations within the file? An example would be :

    IMAGE3 = “Living Room”
    DESC3 = “5.93m (19’5″) x 3.45m (11’4″)”

    I know that it’s possible to include a single quotation if the text file is encapsulated with ” and “, and a double quotation if the text file is encapsulated with ‘ and ‘ – but is there a way for both instances to occur?

    Any help would be greatly appreciated!

    IMAGE3 = "Living Room"
    DESC3 = "5.93m (19'5") x 3.45m (11'4")"

  • Dave Morales

    August 20, 2017 at 12:07 am

    I an trying to do the exact same thing on AE CC 2017 Windows 10, but when I use the syntax you use for the file path with forward slashes:

    /c/test/sourcetext.txt

    …I get a “Syntax Error”.

    If I use back slashes I get “File not Found”.

  • Chris Street

    September 1, 2017 at 6:28 pm

    Never mind my last post. I’ve now coded an app that deals with this 🙂

  • John Gardner

    March 16, 2018 at 6:06 pm

    I am encountering the same issues. I am confident that the syntax I am using is right, as I am just copy/pasting comments here, and then just updating the location of my text file.. any suggestions?

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy