Search code examples
expressionafter-effects

Can an After Effects Expression read a file's contents


Using the ExtendScript shown at the bottom, I'm able to open a YAML file and parse it.

However, when the same code is entered into an After Effects expression, it fails on line 2, saying "Function File is undefined".

Can an Expression open a file and read it's raw contents somehow?

I know that $.evalFile can read a file, but it eval( )-ing everything, and I'm hoping to be able to just read the raw contents of a file. And in my case, I'm hoping to pass the contents to a YAML parser.

1    $.evalFile("yaml.js");
2    var file = File("/tmp/example.yml");
3    if (file.exists){
4      file.open('r');
5      var contents = file.read();
6      var myObject = YAML.eval(contents);
7      alert myObject.company.name
8    }    


Solution

  • I don't think it is possible nor wise. An expression gets evaluated every frame. So you would read in and eval your file each frame.

    You can try to store the file content in the source text property of a text layer and eval from there. But still, this would also happen each frame.