Adobe After Effects Scripting Guide

repository·master·Indexed 41 days ago

https://github.com/docsforadobe/after-effects-scripting-guide

A community-driven guide for scripting in Adobe After Effects, evolved from the original CS6 Scripting Guide. It provides documentation on the global `app` object, including managing projects, GPU acceleration, effects, undo groups, and Multi-Frame Rendering (MFR) introduced in version 22.0. Includes details on executing GUI menu commands, handling external script exit codes, and using global functions for Info panel output.

Tokens
97.6K
Snippets
354
Records
479
Agent score
51%

What's inside After Effects Scripting Guide

  1. Overview of the After Effects Scripting Guide

    master
    The After Effects Scripting Guide is a community-driven repository containing documentation for scripting within Adobe After Effects. It is an evolved version of the original Adobe After Effects CS6 Scripting Guide, updated and adjusted to reflect the modern state of After Effects scripting capabilities.
  2. Manage third-party script settings with the Settings object

    master

    The app.settings object allows you to manage persistent settings for third-party scripts. These settings are stored in the main After Effects preferences file and persist between application sessions.

    Settings are organized by a sectionName and a keyName. Internally, After Effects prepends all saved settings with the prefix "Settings_".

    Important Notes:

    • Data Type: All values are stored and retrieved as Strings. You must manually parse values (e.g., converting a string to a boolean or number) when retrieving them.
    • Size Limit: If a value exceeds 1999 bytes, both getSetting and saveSetting will throw an error.
    • Persistence: Settings are not shared between different versions of After Effects; a new installation will have a fresh settings file.
    • Targeting Files: As of Version 12/CC, methods accept an optional prefType argument to specify a target preference file if the setting is not located in the main preferences file.
    // Conceptual structure in the preferences file:
    // ["Section Name"]
    // "keyName" = "value"
  3. Access the Render Queue items collection

    master

    The app.project.renderQueue.items property returns an RQItemCollection object. This collection represents all items currently visible in the Render Queue panel of the project. It provides access to individual RenderQueueItem objects and allows you to add new items to the queue.

    Note: The collection is 1-indexed; the first RenderQueueItem in the collection is located at index position 1.

  4. Understand the Collection object concept

    master

    A Collection object acts as a logical group of objects or values, similar to an array, allowing access via an index.

    Key characteristics:

    • Read-only: Most collections are read-only. You cannot manually assign objects to them; instead, their contents update automatically as objects are created or deleted within the project (e.g., adding a new layer to a composition).
    • 1-based indexing: Unlike standard programming arrays that start at 0, Collection indexing in After Effects starts at 1.
  5. Understand the After Effects Object Model hierarchy

    master

    The After Effects scripting object model follows the hierarchy of the user interface. The app (Application) object is the root, which contains a Project. The project contains Item objects (like CompItem, FootageItem, or FolderItem) visible in the Project panel. Compositions (CompItem) contain Layer objects (such as AVLayer, TextLayer, or ShapeLayer). Layers contain Property objects, which in turn can contain MarkerValue or keyframe data. The RenderQueue contains RenderQueueItem objects, which manage output modules and render settings.

    Note on Terminology: To avoid confusion between JavaScript and After Effects concepts, this guide distinguishes between:

    • Attribute: Refers to a JavaScript object property.
    • Property (or AE property): Refers specifically to an After Effects layer property.
  6. Use the LayerCollection object to manipulate composition layers

    master

    The LayerCollection object represents a set of layers within a CompItem. You access it via app.project.item(index).layers. It is a subclass of the Collection object, meaning it inherits all methods and attributes from Collection (such as .length) in addition to its own layer-specific methods.

    Use the LayerCollection to manage the layers within a composition, such as counting existing layers or adding new ones from other project items.

    var firstComp = app.project.item(1);
    var layerCollection = firstComp.layers;
    alert("number of layers before is " + layerCollection.length);
    var anAVItem = app.project.item(2);
    layerCollection.add(anAVItem);
    alert("number of layers after is " + layerCollection.length);
  7. Run scripts automatically on startup or shutdown

    master

    After Effects provides two special folders within the Scripts directory for automated execution:

    • Startup folder: Scripts here run automatically after the application is initialized and all plug-ins are loaded. Because scripting shares a global environment, variables and functions defined in startup scripts persist throughout the entire session. Use unique names to avoid overwriting global variables.
    • Shutdown folder: Scripts here run automatically when the application quits (after the project is closed but before other application shutdown processes).
  8. How the CharacterRange object works

    master

    The CharacterRange object is an accessor for a specific span of characters within a TextDocument instance. Unlike the TextDocument object, which typically returns attributes for only the first character, CharacterRange allows you to access and modify attributes (like color, font size, or text content) for a range of zero or more characters.

    Key Behaviors

    • Mixed States: If you attempt to read an attribute (e.g., fillColor) where the characters in the range have different values, the attribute returns undefined rather than a single value.
    • Range Validation: The range is validated against the bounds of the parent TextDocument. If the text length changes (e.g., via character addition or removal), the CharacterRange may become invalid. Use isRangeValid to check this state. Accessing an invalid range will throw an exception.
    • Indexing:
      • characterStart: The first character index.
      • characterEnd: The (last + 1) character index. The number of characters in the range is calculated as characterEnd - characterStart.
    • Insertion Points: A range where the start and end indices are the same is considered an insertion point (zero-length range).
    // Accessing a CharacterRange
    var textDocument = app.project.item(index).layer(index).property("Source Text").value;
    var characterRange = textDocument.characterRange(0, 1); // Range from index 0 to 1
  9. Understand the Fonts object and font proxies

    master

    The app.fonts object provides access to the font ecosystem on your device. After Effects uses internal 'font proxies' to represent fonts.

    Key Behaviors:

    • Soft References: A Font object is a soft reference to a proxy. If the underlying font is removed from the system, referencing that [Font object] will throw an invalid exception.
    • Substituted Fonts: If a font required by a project is missing, After Effects creates an internal proxy that returns true for isSubstitute().
    • Adobe Fonts Sync: By default, After Effects automatically attempts to sync missing fonts from Adobe Fonts asynchronously when a project opens. This cannot be disabled except via app.fonts.freezeSyncSubstitutedFonts.
    • Automatic Replacement: If you install a new font that matches the postScriptName of a currently substituted font, After Effects will automatically replace the substitute with the new real font.
    // Access the Fonts object
    var fonts = app.fonts;
  10. Use the Application object (app)

    master

    The app object is a single global object that provides access to objects and application settings within After Effects. It is always available by its name. You can use its attributes to access specific objects (like app.project) and its methods to control the application (such as creating projects, purging memory, or quitting).

    // The app object is globally available
    var currentProject = app.project;