Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Error in expression for reading a file

  • Error in expression for reading a file

    Posted by Andrew Riebe on May 9, 2014 at 12:22 pm

    Hello,

    I have the following expression:

    var myPath = "~/Desktop/source.txt";
    $.evalFile(myPath);
    try {
    eval(thisComp.name + thisLayer.name);
    } catch (err) {
    "Missing";
    }

    And I keep getting an error message:

    Error at line 1 in property 'Source Text' of layer 1 ('TitleLayer') in comp 'Comp1'. Syntax error.

    Every place I look, I see this expression (or a very similar one) to read text from a file, but this doesn’t seem to work.

    Now, I have After Effects CC. Is there something that I need to do differently in this version, or did I not enable some option?

    Thanks for any help you can provide about this.

    Just so you can see what’s in my source.txt, here it is:

    var Comp1TitleLayer = "Some Text";
    var Comp1SubTitleLayer = "Some More Text";

    (this is just for getting it right so far)

    Brian Nishii replied 11 years, 10 months ago 4 Members · 10 Replies
  • 10 Replies
  • Dan Ebberts

    May 9, 2014 at 3:46 pm

    Setting it up the way you have described here, I get “Some Text”. I’m not sure why your results would be different.

    Dan

  • Andrew Riebe

    May 9, 2014 at 4:00 pm

    Is there some kind of setup that I need to do? I am using OS X Mavericks, perhaps there is something in the Javascript engine that may be the cause?

    Thanks.

  • Dan Ebberts

    May 9, 2014 at 4:08 pm

    Is “~/Desktop” a valid path on a Mac? I ran my test on Win 7.

    Dan

  • Andrew Riebe

    May 9, 2014 at 7:08 pm

    Yes it is. It’s a path variable ~ is equal to /Users/[Username]/. If I enter it into safari, it opens up the file giving the following name: file:///Users/anubisascends/desktop/source.txt. If I use this instead of the ~/Desktop/Source.txt I still get the same result.

    This is really weird, as no one seems to have this problem. I will have to try it out on my Windows computer to see what it might be.

  • Paul

    May 11, 2014 at 6:01 pm

    I’m not sure but if you put:
    file:///Users/anubisascends/desktop/source.txt.
    using 3 ” /// ” after file: that could be a problem

    The idea of using the entire pathname is a good one.

    Cheers.

  • Andrew Riebe

    May 12, 2014 at 1:01 pm

    It’s not actually using 3 forward slashes. It’s broken down like this:

    file://
    /Users/…..

    On a mac, ‘/’ denotes the root drive (just like all unix/linux os’). I tried it on my Windows computer and I don’t get a syntax error, rather I get a file not found error. Here is the path that I used:

    C:\User\andrew.riebe\Desktop\source.txt

    This is a really annoying thing that should simply work (as I can see it working properly in all the tutorials).

    Thanks for the help.

  • Paul

    May 12, 2014 at 4:36 pm

    I’d say try multiple combinations of file paths. Depending on which directory the AE project is in maybe just use a /source.txt.

    Just make sure an put the text file in the after effects project file.

    Just some thoughts.

  • Brian Nishii

    June 25, 2014 at 1:32 am

    @Andrew Riebe,

    Did you ever figure this problem out working on Adobe CC and Mavericks with regards to $.evalFile(myPath) ?

    I’m in the same predicament right now and pulling out what little hair I have left….
    Everything I do returns either a file does not exist or syntax error.

    Playing with path names fixes “file does not exist” but then I get a syntax error on line 1 – with or without the “var”:

    var myPath = “~/Desktop/source.txt”;
    $.evalFile (myPath);
    try {
    eval (thisComp.name) [0];
    }catch (err){
    “Missing”;
    }

    If you found a fix, please share.

    Thanks!

  • Paul

    June 25, 2014 at 3:21 am

    I don’t work much with AE lately so sorry I cannot be of much help.

    I’d just check and re-check my code …..maybe run simpler versions if possible.

    Sorry….good luck to ya.

  • Brian Nishii

    June 25, 2014 at 5:50 am

    Thanks for the response. FINALLY figured it out.

    You’r right – simplify what you’re doing to confirm paths are working, and then check, re-check, and re-re-check code….

    For anyone working on a Mac, it really behooves you to write the .txt file in a code-friendly text program like TextWrangler. (in a large font …he he)

    Thanks!

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