Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reading internal source text.

  • Reading internal source text.

    Posted by Obed Ampong on August 15, 2018 at 5:16 pm

    Hello,
    I tried using the $.evalFile to locate source text external data and After Effects keep telling me ” the file or the folder does not exist”. So I tried to import the data manually by copying the data and removing read the path part of the expression. The modified expression is the second one however After Effects only read the individual characters of the comp name. Thus the modified expression resulted “C” instead of “Text 0” for (thisComp.name)[0] , “o” instead of “Text1” for(thisComp.name)[1] and “m” instead of “Text 2” for(thisComp.name)[2] .
    Please, could someone kindly help me out?

    Thanks in advance
    Obed

    myPath = "~C:/Users/Greatman/Documents/data/source.txt";
    $.evalFile(myPath);
    eval(thisComp.name)[0];

    var comp1 = ["Text 0", "Text 1", "Text 2"];
    (thisComp.name)[0];

    Obed Ampong replied 7 years, 9 months ago 2 Members · 14 Replies
  • 14 Replies
  • Dan Ebberts

    August 15, 2018 at 5:26 pm

    If you put some legal JavaScript like this in your file:

    txt = [“Text 0”, “Text 1”, “Text 2”];

    Then you should be able to access the array elements of txt with an expression like this:

    myPath = “/c/test/test.txt”;
    $.evalFile(myPath);
    txt[0]

    I’m not sure why you would want to get thisComp.name involved.

    Dan

  • Obed Ampong

    August 15, 2018 at 5:39 pm

    Hi Dan,
    thanks for the reply. I intended duplicating the comp for it to automatically change the text for the rest of the project because I have a lot of data to work with.

    Obed

  • Dan Ebberts

    August 15, 2018 at 6:13 pm

    Then I guess you could do something like this:

    myPath = “/c/test/test.txt”;
    $.evalFile(myPath);
    idx = thisComp.name.substr(-1)-1;
    txt[idx]

    Dan

  • Dan Ebberts

    August 15, 2018 at 6:18 pm

    Wow, I’m surprised that worked. I meant to do it this way:

    myPath = “/c/test/test.txt”;
    $.evalFile(myPath);
    idx = parseInt(thisComp.name.substr(-1)-1,10);
    txt[idx]

    Dan

  • Obed Ampong

    August 15, 2018 at 6:44 pm

    I got an error: “file or folder does not exist” after using the file local address on the pc

  • Dan Ebberts

    August 15, 2018 at 6:56 pm

    Using your original path? Try it this way:

    myPath = “/c/users/greatman/documents/data/source.txt”;

    Dan

  • Obed Ampong

    August 15, 2018 at 7:13 pm

    yea, I tried the path you suggested and the error was “unterminated string constant”
    thanks

    Obed

  • Dan Ebberts

    August 15, 2018 at 8:17 pm

    You can get that error if there’s a problem with your text file (like a missing quotation mark).

    By the way, if you have AE CC 2018, there are better ways to do this that don’t involve the $.eval() hack.

    Dan

  • Obed Ampong

    August 15, 2018 at 10:10 pm

    Yea, OK. that will be great. please, could you let me know?

  • Dan Ebberts

    August 15, 2018 at 11:05 pm

    OK, simple example. Say you have a comma-separated (CSV) file named “test.csv” like this:

    1,2,3,4
    Text 0,Text 1,Text 2,Text 3

    (the first row is just the column headers–the data starts in the 2nd row)

    You import that into your project. Then you could have a text expression like this:

    idx = parseInt(thisComp.name.substr(-1)-1,10);
    footage(“test.csv”).dataValue([idx,0])

    which would pick the data corresponding the column identified by the last character in your comp name. Comp 1 gets Text 0, etc.

    This won’t work if you aren’t using CC 2018.

    Dan

Page 1 of 2

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