Passing the result of a python script to an ExtendScript `.jsx` file

孤街醉人 提交于 2019-12-10 23:04:12

问题


So, I'm writing a python script that gets data from a google sheet and returns it back to an ExtendScript script that I'm writing for After Effects.

The relevant bits are :

getSpreadsheetData.py

def main():
    values = getSpreadsheetRange("1M337m3YHCdCDcVyS4fITvAGJsw7rGQ2XGbZaKIdkJPc", "A1:Q41")
    return processValues(values)

afterEffectsScript.jsx

var script_file = File("getSpreadsheetData.py");
var results = script_file.execute();
$.writeln(results);
alert("done!");

So, I have three questions :

  1. How do I pass variables from the afterEffectsScript.jsx to the python script (for example the spreadsheet id and range)?

  2. How do I get a return from the python script and return it back to the jsx file?

  3. How do I make my afterEffectsScript to work async so that it can wait for the python script to get what it needs...

Thanks in advance for the advice!

-P


回答1:


After Effects has the possibility to call system commands and get the result of stdout.

var cmd = "pwd";
var stdout = system.callSystem(cmd);
$.writeln(stdout);

Take a look into the AE Scripting Guide




回答2:


You can pass variables via setting environment variables. Small example how call external script with args from extendscript:

var script_file = File("getSpreadsheetData.py");
$.setenv("arg_1", "arg1_value");
$.setenv("arg_2", "arg2_value");
script_file.execute();

You python script should start with reading this varibles from environment: Access environment variables from Python



来源:https://stackoverflow.com/questions/42863672/passing-the-result-of-a-python-script-to-an-extendscript-jsx-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!