1
votes

I am working on an extendscript code (Adobe After Effects - but it is basically just javascript) which needs to iterate over tens of thousands of file names on a server. This is extremely slow in extendscript but I can accomplish what I need to in just a few seconds with python, which is my preferred language anyway. So I would like to run a python file and return an array back into extendscript. I'm able to run my python file and pass an argument (the root folder) by creating and executing a batch file, but how would pass the result (an array) back into extendscript? I suppose I could write out a .csv and read this back in but that seems a bit "hacky".

1
You can do it. I can't remember how, but read the docs. Extendscript has some features JS doesn't. Specific directives and such. - dgo
I searched around the JavaScript tools guide for a bit and all I came up with is the .execute() method, which will run the batch file but I don't know how to get the array back into AE. Any specific ideas? - Spencer
From the JS Tools Guide re: the fileObj.execute() method "Returns true immediately if the application launch was successful." so I can't return anything from that... - Spencer
Have Python write "done" to a file. Then use a Javascript timer to check the file in a loop until it's done, and have a callback to run when it's finished. Something like that seems like your best bet. You could also import a 3rd party JS library that supports promises and/or deferred objects. That's what I'd do. - dgo
@user1167442 check out ariestav's answer below if you're curious - it is just what I needed! - Spencer

1 Answers

5
votes

In After Effects you can use the "system" object's callSystem() method. This gives you access to the system's shell so you can run any script from the code. So, you can write your python script that echos or prints the array and that is essentially what is returned by the system.callSystem() method. It's a synchronous call, so it has to complete before the next line in ExtendScript executes.

The actual code might by something like:

var stdOut = system.callSystem("python my-python-script.py")