-
script loading a function from text file
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 expressionvar 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.