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
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()
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)
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);
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
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])
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)
importFile() works a little like this:
new ImportOptions().file = new File("...FilePath/My File.jpg"); app.project.importFile(file)
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()
importFileWithDialog() meanwhile opens up the import footage dialogue box, for the end user to select their file.
app
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()
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)
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);
item() refers specifically to a single item inside of your project - be it a composition, solid, or what have you. Like so:
app.project
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])
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)
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
And can move items into the folder after the fact, by setting the item's parentFolder attribute:
app.newProject()
Once you've created a composition, you can set it as your active item by using openInViewer()
app.open(file)
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);
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
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!

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
