Copy link to clipboard
Copied
Hi, I need a solution to open a specific project file and then execute a js script. This needs to be an automated process executed through python in Maya. The script is a list of instructions which updates a template project with shot and camera information which it reads from a json file. This script works correctly when run manually with the template project already open. But I need an automated process (client's request) to eliminate steps for artists.
I've tried the following without success:
os.system("path/projectFile.aep")
works on some computers and not others. When it works, it opens the correct project file but can't execute the script.
subprocess.run([app,"path/projectFile.aep" ])
will open the correct project file (though I have not tested it on other machines)
app = systemPath/AfterFX.exe
js_file = path/automationSript.js
subprocess.run([app, "path/projectFile.aep", "var a = new File("+js_file+" ;, a.open();, eval(a.read());])
opens after efffects to the correct project file but does not execute the js script.
subprocess.run([app,"var a = new File("+js_file+" ;, a.open();, eval(a.read());])
opens after efffects but fails when trying to execute the js script.
Caveats:
The correct project file needs to be opened first before the script executes. This is because the scipt uses the file path of the current project to locate the json file with all the necessary data, and the script updates pre-built comps, layers, sliders etc within that project file. This template is editable and customizable by client's supervisors and needs to maintain that flexibility, so the automation script can't build all that from scratch. It needs to be run after that project file is open in the application.
Please help.
thanks
1 Correct answer
You need to use a file object, not just a path
app.open(new File(project_file))
Copy link to clipboard
Copied
I'm getting closer with:
project_file = "path/projectFile.aep"
subprocess.Popen([app ,'-s', "app.open('"+ project_file+"'); var a = new File('"+script_file+"'); a.open(); eval(a.read()); app.exitAfterLaunchAndEval = false;"])
but...
subprocess.Popen([app ,'-s', "app.open('"+ project_file+"')])
This fails because it says my project_file is not a file or folder. It is, and the path and filename are correct, I've verified it by running: os.system(project_file)
Please help me understand this error.
Still need help, thanks
Copy link to clipboard
Copied
You need to use a file object, not just a path
app.open(new File(project_file))
Copy link to clipboard
Copied
The full python subprocess script for anyone else trying to do the same thing:
import subprocess
script_file = 'path/script.js'
project_file = 'path/project.aep'
app = getUserVersionOfAfterEffects() #create a function to do this, don't assume
doThis = "app.open(new File ('"+ project_file+"')); " #opens AE to correct project
doThis+= "var a = new File('"+script_file+"'); a.open(); eval(a.read()); " #loads and executes script
doThis+= "app.exitAfterLaunchAndEval = false;" #optional
subprocess.Popen([app, '-s', doThis])
Copy link to clipboard
Copied
app = getUserVersionOfAfterEffects() #create a function to do this, don't assume
what do you mean by this?
is this just the path to AfterFX.exe?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
yep. it's a function to get the path to the AfterFX.exe.
def getUserVersionOfAfterEffects():
app = 'C:/Program Files/Adobe/Adobe After Effects 2021/Support Files/AfterFX.exe'
if not os.path.exists(app):
fnd = 'AfterFX.exe'
results = findFile(fnd, 'C:/Program Files/Adobe')
if results:
app = results[-1]
return app
def findFile(findThis, startFolder,**kwargs):
''' This is a stripped down version of my findFile function. The part shown here I found on the internet.'''
lst =[]
if os.path.isdir(startFolder):
for root,dirs,files in os.walk(startFolder):
for filename in files:
if findThis in filename:
found = os.path.join(root).replace('\\','/')
lst.append(found)
return lst

