AE Scripting



Introduction

After Effects 6.5 includes a very powerful upgrade to AE's scripting implementation. They might have teased us with a taste of scripting in 6.0, but this is the real deal. You now have the power (for good or evil) to create amazing scripting applications for After Effects. The potential is enormous.

Scripting vs. Expressions

First, let's look at some of the similarities and differences between AE scripting and expressions They are both JavaScript based and share a lot of the same AE-specific syntax. There is also some overlap in functionality. That is, there are some situations where you could use either expressions or scripting to get the job done, but usually your requirements will fall clearly into one camp or another.

For the most part, these are very different beasts indeed. Expressions are live at each frame. If you move the time marker, all the expressions in your comp will run to create the correct image at that time. When you render, your expressions will run at each frame. Expressions are applied to properties of layers, cameras, effects, etc., but they can't create anything.

In contrast, scripts are run on demand. You run the script, it does its job, you move on. Scripts can create things like projects, comps, layers, cameras, keyframes, etc. You can apply effects with scripts. You can even create expressions with scripts. Also, anything having to do with job control or render automation is clearly within the domain of scripting. You can even create a user interface for your script. Your typical AE script will contain more code than your typical expression and you may also notice that scripts will often be implemented with more formal coding standards than your typical expression (using "var" to declare variables is one example).

Why We're Here

I'm assuming you're here because you want to learn how scripting works and how you might create your own scripts to help you with your design projects.

At this point, let me be perfectly candid. Scripting is not for wimps. Let's compare writing scripts with writing expressions. With expressions, you can use the pick whip to create a complex expression without having to know too much about JavaScript or the AE-specific additions to the language. There's nothing like that to help you create scripts. To be able to write scripts you're going to need to be very familiar with the AE Scripting Guide (included on the CD) and the syntax of JavaScript. Now the good news. The AE Scripting Guide is an amazingly good and thorough resource. Throw in a good book on JavaScript and you're in business. With those two resources and a collection of sample scripts you should be able to look at any script and figure out what it's doing and how it works.

And that's really the best way to learn. AE comes with a lot of sample scripts and there are a lot of examples in the scripting guide. So the trick is to find one or more scripts that have examples of what you're trying to do and use them to piece together your own script.

For example, in the AE "Scripts" folder there is a "(demos)" folder that contains a script I wrote called "ShapetimeInsanity" that includes code that: creates a project; creates a comp; creates layers; sets the layer blend mode; adds masks; and sets keyframes for position, rotation, opacity, and scale. So if your script needs to do one or more of those things, you can look inside ShapetimeInsanity to see how someone else did it. So the message here is to examine the sample scripts (and any others you can find here and elsewhere on the internet) so you will know where to locate the snippets of code that you can weave together to create that scripting masterpiece that you have envisioned.

That being said, let's get back to the purpose of this site. What I'm going to do here is walk you through some examples. We'll start with a very simple script and explain how it works. Then we'll increase the complexity. We'll look at more examples and case studies. We'll cover subjects like style and good housekeeping that will make your scripts more useful and readable for others (and yourself when you look at them again months from now). We'll examine using dialogs to create a user interface for your scripts. We'll also take a look at how to use the JavaScript debug console. My hope is that by walking through the examples and case studies you find here, you will gain the knowledge that will prepare you to take on scripting projects of your own.


Good luck and enjoy your journey!


Dan