After Effects / ExtendScript: Using libraries and importing .jsx files?
Asked Answered
S

1

13

I am new to After Effects scripting but have much experience with JavaScript in the browser.

  1. How do I import .jsx files?
  2. Can I use js libraries such as underscore.js etc?
  3. What are some good resources for AE scripting? (Ideally infographics projects)
Schmooze answered 3/2, 2013 at 20:20 Comment(0)
D
28
  1. To include a .jsx next to your script

use:

#include "includeme.jsx"

EDIT 2:

You can also include files using the following syntax:

//@include "includeme.jsx"

Which (IMHO) is the better way. It wont break a linter and is more javascript-ish.

  1. You can use plain old javascript (ES3 Syntax). If the libraries you include use some browser specific js (like console.log()) you will get an error

  2. Best resource is the After Effects scripting guide. There are also lots of open source scripts on http://aescripts.com that you can examine

EDIT 1: You can also include a file like this.

var path = ((File($.fileName)).path); // this is the path of the script
// now build a path to another js file
// e.g. json lib https://github.com/douglascrockford/JSON-js
var libfile = File(path +'/_libs/json2.js');
if(libfile.exists){
  $.evalFile(libfile);
}

Edit 3: Old link to AE scripting docs was broken. Updated the link

Determination answered 4/2, 2013 at 15:7 Comment(6)
Thanks Fabian! I tried that earlier but then it didn't work. Not sure what I did wrong.Schmooze
Will the //@ syntax work for other pre-processor directives, such as #target indesign or #strict on?Pesade
@Pesade I think //@target works. //@strict I don't know. Why don't you give it a try and report back? ;)Determination
@fabianmoronzirfas, I can't tell any difference. With that line, deleting that line, changing it to #strict off, etc. The command (when set to 'on') is supposed to throw a runtime error when an attempt is made in the script to write to a read-only property. I put in the line app.activeScriptUndoMode = UndoModes.AUTO_UNDO; near the top of the script to test it. However, I get the error no matter what that #strict line is.Pesade
poor old extendscript. It is so broken in some parts. Thanks for the reportDetermination
Modern link to the AE Scripting guide, since the one in the answer is rotten: ae-scripting.docsforadobe.dev/index.htmlChalybeate

© 2022 - 2024 — McMap. All rights reserved.