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
1653
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

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.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

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.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

How to implement panel drag and drop adjustment function similar to VSCode in front-end development? How to implement panel drag and drop adjustment function similar to VSCode in front-end development? Apr 04, 2025 pm 02:06 PM

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...

See all articles