Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions script loading a function from text file

  • script loading a function from text file

    Posted by Xavier Gomez on August 11, 2012 at 10:45 pm

    Hello,

    i’ve got some small problem while writing a (UI)script.

    The user should be able to write a js function in the AE interface
    (whatever way, at the moment i’m using the expression box…)
    The script reads it as a string, opens a text file,
    copies the string into that file, evaluates it and close.

    Then it uses the function as if it was part of the script itself.

    I was very surprised but it works. Still there is a problem: it only works at the second execution of the script.
    To be more precise, the user enters the fonction as a string, clicks the run button, the script runs but doesnt take into account the new input. Clicking “run” again gets the job done correctly.
    So i repeated the open/copy/evaluate/close actions in the script immediately after the first one and now it works perfectly. But i dont understand why !

    The code looks like this:


    // this reads and slices the expression

    var functionString = waveLayer.effect(someEffect).property("Point").expression;
    var delIndex = functionString.indexOf("//DO NOT REMOVE THIS LINE");
    functionString = functionString.slice(0,delIndex);

    // open/copy/evaluate/close, 1st time

    functionFile = new File ("./Scripts/ScriptUI Panels/ZZZZZ.jsx");
    functionFile.open("e");
    functionFile.write(functionString);
    $.evalFile(functionFile);
    functionFile.close();

    // at this stage the function isnt ready to use yet

    functionFile2 = new File ("./Scripts/ScriptUI Panels/ZZZZZ.jsx");
    functionFile2.open("e");
    functionFile2.write(functionString);
    $.evalFile(functionFile2);
    functionFile2.close();

    // now it is ready

    If someone is comfortable with this (i’m definitely not), i’d love to have an explanation !

    Xavier.

    Xavier Gomez replied 14 years ago 2 Members · 3 Replies
  • 3 Replies
  • Xavier Gomez

    August 11, 2012 at 10:58 pm

    Wow !
    i just realised by reading another recent post in the forum that there is an eval() function and there is no need to copy the string to an actual file to evaluate it !!! Sorry for that.

    I could delete this post but i’d still appreciate an explanation for the behaviour described above.

  • Dan Ebberts

    August 11, 2012 at 11:29 pm

    My hunch is that you have to do the close() before you do the $.evalFile().

    Dan

  • Xavier Gomez

    August 14, 2012 at 7:20 am

    So you have good knowledge and also a good hunch. That was it. Thank you !

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