Home Web Front-end JS Tutorial Scripting: After Effects Projects and Compositions

Scripting: After Effects Projects and Compositions

Dec 08, 2024 pm 04:31 PM

Scripting: After Effects Projects and Compositions

Contents
Introduction
Application
Project
Folders And Compositions
Example
Quick Tips
Conclusion

Introduction

In this article I'll be going through some of the basics of navigating After Effects projects and compositions using a script. I'll be referencing some of the most useful parts of the scripting guide, and showing off some practical examples of how it works.

Let's get started.


Application

app
Copy after login
Copy after login
Copy after login

app references the application After Effects itself. To reference anything inside After Effects, you'll need to start by telling your script to look at the application.

While you can reference the settings, files and the computer system After Effects is installed on (i'll be going into these options in another article), it is more than likely the main object you will need to reference after the application is an After Effects project.

app.newProject()
Copy after login
Copy after login
Copy after login

newProject() creates a new, empty project. You'll be prompted by After Effects if you'd like to save your current work before this happens.

app.open(file)
Copy after login
Copy after login
Copy after login

open() meanwhile allows you to open an existing project. Leaving the brackets blank, it will bring up the open project dialogue box as if navigating to File > Open Project... in the After Effects menu. Alternatively, you can reference a file inside the brackets to open a specific project.

project = new File ("...FilePath/AE Project.aep");
app.open(project);
Copy after login
Copy after login
Copy after login

You will need to create a new File() to locate the file from within your script. I prefer to store this in a variable to keep things tidy. Again, you'll be prompted to save your current project before the file opens.


Project

app.project
Copy after login
Copy after login
Copy after login

project references the current project open in After Effects. From here, we can access all the items from within our project, create new ones, and access the render queue.

app.project.save([file])
Copy after login
Copy after login

save() saves the project. Without adding the option of a file, or if the project has not been previously saved, this method will bring up the save dialogue for the user to save their project. Remember - you need to create a new File in your project before you can reference it in this method.

app.project.importFile(importOptions)
Copy after login
Copy after login

importFile() works a little like this:

new ImportOptions().file = new File("...FilePath/My File.jpg");
app.project.importFile(file)
Copy after login

I'll be going into importing files in more detail in another article. But as a quick overview, you use this method to import files into your project. Not only do you need to create a new File, but you also have to create new ImportOptions to specify what you are importing, and how. This allows us to do things like import image sequences, import files as, and force alphabetical order.

app.project.importFileWithDialog()
Copy after login

importFileWithDialog() meanwhile opens up the import footage dialogue box, for the end user to select their file.

app
Copy after login
Copy after login
Copy after login

renderQueue grants us access to the render queue, and allows us to set render settings and even render compositions. I will be going more into this in another article.

app.newProject()
Copy after login
Copy after login
Copy after login

activeItem refers to the current item being viewed, usually a composition, footage layer, placeholder, or solid. It only references one item at a time, and returns a null if multiple items are active, or if none are active. It can be handy to reference the active composition, for scripts which add layers or affect what the user is currently working on in some way. Note that this isn't the same as an item being selected.

app.open(file)
Copy after login
Copy after login
Copy after login

selection refers to all the items currently selected inside the project panel. This is what you need when referencing the items selected, rather than the item that is active.

project = new File ("...FilePath/AE Project.aep");
app.open(project);
Copy after login
Copy after login
Copy after login

item() refers specifically to a single item inside of your project - be it a composition, solid, or what have you. Like so:

app.project
Copy after login
Copy after login
Copy after login

The index represents either the index number of the item inside the project window, or, can also refer to the name of the layer.

app.project.save([file])
Copy after login
Copy after login

items meanwhile refers to the collection of items inside your project. It is used to create new compositions and folders.


Folders And Compositions

This brings us nicely onto folders and compositions.

app.project.importFile(importOptions)
Copy after login
Copy after login

addFolder() creates a new folder for your project. Make sure the name argument is a string (in " " or ' ').

addComp() however has many more arguments to consider. This is because there is a lot of information that is needed to create a new composition:

Argument Description
name The name of the composition. Needs to be a string (in " " or ' ')
width The width of your composition
height The height of your composition
pixelAspect The pixel aspect ratio. You are almost certainly looking to set this to Square Pixels, which you can do by setting the ratio to 1. Any other pixel aspect ratio can be set by entering the correct ratio (for example, Anamorphic 2:1 can be set by entering 2, and D1/DV PAL Widescreen can be set by entering 1.46).
duration The duration of the composition in seconds
frameRate The frame rate of the composition

You can create new comps inside of folders by referencing the folder instead, like this:

app
Copy after login
Copy after login
Copy after login

And can move items into the folder after the fact, by setting the item's parentFolder attribute:

app.newProject()
Copy after login
Copy after login
Copy after login

Once you've created a composition, you can set it as your active item by using openInViewer()

app.open(file)
Copy after login
Copy after login
Copy after login

Example

Using a little of what I've covered, here is a short script which allows you to open a new project, create 2 folders and 2 compositions, and add one comp to the other as a precomp.

project = new File ("...FilePath/AE Project.aep");
app.open(project);
Copy after login
Copy after login
Copy after login

Quick Tips

You'll find, after running this script, if you were to press undo in After Effects, it will only undo each action one at a time. Most of the time this isn't ideal, as scripts often undergo many actions, making this very time consuming and annoying for the end user.

app.project
Copy after login
Copy after login
Copy after login

That is where beginUndoGroup() and endUndoGroup() come in. They allow you to group the script's actions together, so that they can be undone in one motion. The undoString is what you will see next to the undo option in After Effects. While you don't necessarily need to add endUndoGroup() if you only have one instance of beginUndoGroup() in your script (as it will close automatically), it is good practice to add it to the end of your script, to keep your script tidy.


Conclusion

I hope this has helped to shed some light on how to reference After Effects projects and compositions while making your After Effects scripts. In the next article, I will go over creating pop up windows for users to interact with your scripts.

Have any questions? Something wrong here or not working? Let me know in the comments.

The above is the detailed content of Scripting: After Effects Projects and Compositions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript: Exploring the Versatility of a Web Language JavaScript: Exploring the Versatility of a Web Language Apr 11, 2025 am 12:01 AM

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration) Apr 11, 2025 am 08:22 AM

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

From C/C   to JavaScript: How It All Works From C/C to JavaScript: How It All Works Apr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Building a Multi-Tenant SaaS Application with Next.js (Backend Integration) Apr 11, 2025 am 08:23 AM

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

See all articles