Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression Code from external text file

  • Expression Code from external text file

    Posted by Andy Kreutzberg on December 10, 2012 at 4:28 pm

    Hello,

    again i seek the help of this community. It’s nothing big this time, I am sure the solution is a quick one.

    Here is the problem:

    Recently, i have been looking into ways of having text layers load their source text property from external text documents. It is pretty straight forward. I am using a slightly modified code based on this: https://www.graymachine.com/2009/04/expressions-and-external-documents-revisited/

    Now instead of referencing source text only, I want to have all expressions that i am using in external files stored on a fixed location of a server. And here is where it fails. I tried putting a simple expression into a text file and have it load… not working. Here is what i have:

    a text layer named “year”, that contains a company name as well as a dynamically updating date information. This expression is featured in the source text parameter of the text layer “year”

    x=”© name”;
    D = new Date(Date(0));
    “r” + “r” + “r” + “r” + x + ” ” + D.getFullYear();

    I have put that into a text document in the following way, similar to regular source text information:

    var year = [x=”© name”;
    D = new Date(Date(0));
    “r” + “r” + “r” + “r” + x + ” ” + D.getFullYear();]

    Thing is, if i replace the expression within the [] by plain text, something like “Hello”, it will be displayed properly. If i put the above expression in there, my error catch gives me notfound, which means something is broken. How can i make the above expression work from the external document? Or does this only work with text only and not with entire lines of code?

    Andy Kreutzberg replied 13 years, 5 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    December 10, 2012 at 8:27 pm

    I just tried this Source Text expression:

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

    With this text file:

    x=”© name”;
    D = new Date(Date(0));
    x + ” ” + D.getFullYear();

    And got this result:

    © name 2012

    (AE CS6 on Windows)

    Dan

  • Andy Kreutzberg

    December 11, 2012 at 11:16 am

    Ah, so you left off the variable of the layer name. It seems to work when just the code is the content of the text file as it would appear in after effects. That simple solution makes it work.

    Is there maybe a solution to have all the code for all layers in one file, similar to the “var layer name” approach, to assign the code to the specific layers and properties? Just out of curiosity. The one file per property approach should work anyways.

  • Dan Ebberts

    December 11, 2012 at 2:58 pm

    I suppose in the text file you could assign each expression (as a string) to a variable and then the expression for each property could load the file and do an eval() on the appropriate variable. It all seems a little messy to me, because every property with an expression would have to load the text file on every frame, but I guess it’s possible.

    Dan

  • Andy Kreutzberg

    December 11, 2012 at 3:28 pm

    Now that you say it, yes it makes more sense to do one file per property. If each property has to eval a huge text file just to find the piece of expression that it needs, the whole process will become slower as the amount of layers and expressions increases.

    I have already made some testing with the one text file per property method and there does not seem to be a significant slow down compared to having the expressions inside after effects.

    Always nice to learn something new. Thanks Dan.

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