Adobe After Effects Scripting Guide
repository·master·Indexed 41 days ago
https://github.com/docsforadobe/after-effects-scripting-guideA 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.
What's inside After Effects Scripting Guide
- 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.
Manage third-party script settings with the Settings object
masterThe
app.settingsobject 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
sectionNameand akeyName. 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
getSettingandsaveSettingwill 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
prefTypeargument 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"Access the Render Queue items collection
masterThe
app.project.renderQueue.itemsproperty returns anRQItemCollectionobject. This collection represents all items currently visible in the Render Queue panel of the project. It provides access to individualRenderQueueItemobjects and allows you to add new items to the queue.Note: The collection is 1-indexed; the first
RenderQueueItemin the collection is located at index position 1.Understand the Collection object concept
masterA
Collectionobject 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.
Use the MaskPropertyGroup object
masterTheMaskPropertyGroupobject encapsulates mask attributes for a specific layer. It is a subclass of thePropertyGroupobject, meaning it inherits all methods and attributes fromPropertyGroupandPropertyBase. You can access a mask group via the path:app.project.item(index).layer(index).mask.Understand the After Effects Object Model hierarchy
masterThe After Effects scripting object model follows the hierarchy of the user interface. The
app(Application) object is the root, which contains aProject. The project containsItemobjects (likeCompItem,FootageItem, orFolderItem) visible in the Project panel. Compositions (CompItem) containLayerobjects (such asAVLayer,TextLayer, orShapeLayer). Layers containPropertyobjects, which in turn can containMarkerValueor keyframe data. TheRenderQueuecontainsRenderQueueItemobjects, 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.
Use the RenderQueue object to manage rendering
masterTheapp.project.renderQueueobject provides access to the data and functionality of the After Effects Render Queue panel. It allows you to manage the render automation process, including starting, pausing, and stopping renders, as well as accessing specific items in the queue viaRenderQueueItemobjects.Use the LayerCollection object to manipulate composition layers
masterThe
LayerCollectionobject represents a set of layers within aCompItem. You access it viaapp.project.item(index).layers. It is a subclass of theCollectionobject, meaning it inherits all methods and attributes fromCollection(such as.length) in addition to its own layer-specific methods.Use the
LayerCollectionto 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);Run scripts automatically on startup or shutdown
masterAfter Effects provides two special folders within the
Scriptsdirectory 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).
How the CharacterRange object works
masterThe
CharacterRangeobject is an accessor for a specific span of characters within aTextDocumentinstance. Unlike theTextDocumentobject, which typically returns attributes for only the first character,CharacterRangeallows 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 returnsundefinedrather 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), theCharacterRangemay become invalid. UseisRangeValidto 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 ascharacterEnd - 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- Mixed States: If you attempt to read an attribute (e.g.,
Understand the Fonts object and font proxies
masterThe
app.fontsobject 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
trueforisSubstitute(). - 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
postScriptNameof a currently substituted font, After Effects will automatically replace the substitute with the new real font.
// Access the Fonts object var fonts = app.fonts;Use the Application object (app)
masterThe
appobject 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 (likeapp.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;