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)
dani
  • 4,880
  • 8
  • 55
  • 95

1 Answers1

27
  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

fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
  • Thanks Fabian! I tried that earlier but then it didn't work. Not sure what I did wrong. – dani Feb 04 '13 at 15:43
  • Will the `//@` syntax work for other pre-processor directives, such as `#target indesign` or `#strict on`? – Sturm Sep 07 '16 at 20:27
  • 1
    @Sturm I think //@target works. //@strict I don't know. Why don't you give it a try and report back? ;) – fabianmoronzirfas Sep 08 '16 at 04:54
  • 1
    @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. – Sturm Sep 12 '16 at 16:57
  • poor old extendscript. It is so broken in some parts. Thanks for the report – fabianmoronzirfas Sep 13 '16 at 06:19
  • 1
    Modern link to the AE Scripting guide, since the one in the answer is rotten: https://ae-scripting.docsforadobe.dev/index.html – cvbattum Oct 14 '22 at 11:47