2

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

2 Answers2

1

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

Community
  • 1
  • 1
emax
  • 511
  • 1
  • 4
  • 13
  • Aha, this sounds like a solution to points #1 & #2! Is there a way of listening to when environmental variables change values to answer point #3? I assume that I'd then manipulate a environmental variable from python & access it from the ExtendScript rather than use the `results` variable as I've done here? – PookageHayes Mar 19 '17 at 11:56
  • Other issues are discussed here http://stackoverflow.com/questions/18969372/execute-external-script-in-extendscript-for-illustrator – emax Mar 19 '17 at 15:52
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

fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41