Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Replacing a string of text from a text file (with a small twist)

  • Replacing a string of text from a text file (with a small twist)

    Posted by David Newman on October 2, 2019 at 10:29 pm

    Hi there,

    I have an expression on my text layer which evaluates a variable in a text file to get a string:

    $.evalFile(“/D:/main.txt”);
    eval(thisLayer.name)

    And inside the main.txt:
    string1 = “Hello world”

    And finally the text layer name is appropriately called “string1” so that the string is evaulated correctly and the text on screen is “Hello world”.

    What I really want to do is to have more than one strings in my text file, like this:
    string1 = “Hello world”
    string2 = “Hello Mars”
    string3 = “Hello Pluto”
    text1 = “Human”
    text2 = “Martian”
    text3 = “Plutonian”

    And I want to define multiple strings by having two text layers called “string” and “text” and having a null object above simply called 1, 2 or 3 to change the text.
    And have the expression as:

    $.evalFile(“/D:/main.txt”);
    eval(thisLayer.name+(index-1))

    But it doesn’t work. Hope this vaguely makes sense. I’ve managed to achieve the effect adding the layer name to a slider value, but I’d rather do it with another layer. Thanks.

    David Newman replied 6 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 2, 2019 at 11:35 pm

    I think you’re maybe making it more complicated than it needs to be. If you use this as your text file:

    string1 = “Hello world”
    string2 = “Hello Mars”
    string3 = “Hello Pluto”
    text1 = “Human”
    text2 = “Martian”
    text3 = “Plutonian”

    Then once you do this:

    $.evalFile(“/D:/main.txt”);

    those six variables (string1, string2, etc) should exist in the expression.

    So this:

    $.evalFile(“/D:/main.txt”);
    string2

    Should give you “Hello Mars”, so I wouldn’t think you’d need to do an eval() to select which string gets displayed.

    It might be even better to do something like this with your text file:

    strings = [“Hello world”, “Hello Mars”, “Hello Pluto”];
    texts = [“Human”, “Martian”, “Plutonian”];

    Then an expression like this:


    $.evalFile("/D:/main.txt");
    idx = 2;
    strings[idx] + "\r" + texts[idx]

    Would give you:

    Hello Pluto
    Plutonian

    Then you just need a clever way to select idx…

    Dan

  • David Newman

    October 3, 2019 at 3:44 pm

    Thanks for your reply, Dan.

    Lots of useful tips in there!

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