Home Web Front-end JS Tutorial Scripting: Creating Windows For Your After Effects Scripts

Scripting: Creating Windows For Your After Effects Scripts

Jan 22, 2025 pm 08:35 PM

Contents
1. Introduction 6. Buttons
2. Windows 7. Options
3. Groups 8. Example
4. Panels 9. Conclusion
5. Text

Introduction

Creating a window for a script is ideal when you need the end user to input information, and display instructions. In this article I'll go through the basics of creating a window for your AE script using some basic javascript and Adobe Extendscript Toolkit CC.


Windows

To make your window, it's very simple:

//New Window
var mainWindow = new Window("palette", "Title", undefined);
Copy after login
Copy after login
Copy after login

new Window() is the argument to create the window. Then, inside you need to specify the type, title and bounds. A palette window is suitable for After Effects scripts, and leaving the bounds as undefined is also recommended, as the size and position can be affected later.

To call your window:

mainWindow.show();
Copy after login
Copy after login

Since there is nothing currently in the window, this will simply call a small window to show it is working.

Screenshot of window with nothing in it


Groups

The next thing to do is to create an object to house information for your window.

The "group" allows you to organize objects inside of it. Before mainWindow.show() add this line to your script:

group01 = mainWindow.add("group", undefined, "Group 01");
Copy after login
Copy after login

We add the group to our mainWindow, outlining the type, bounds, and text properties. Since we are adding a group, the first argument is "group". Again, you can leave the bounds undefined. Lastly, include what you want the group to be named. This is not displayed by default in the window.

Screenshot of a group object with the text

The default orientation of panels is by row. If you want to change this to sort of column, you can do so by adding this to your script:

group01.orientation = "column";
Copy after login
Copy after login

Panels

However, if you do want the name of the group to be visible, you could consider using a "panel" object instead. This type of object is helpful for sectioning off parts of the window:

group02 = mainWindow.add("panel", undefined, "Group 02");
Copy after login
Copy after login

It has the same properties as the "group" object, but displays slightly differently.

Screenshot of a panel object with the text

The default orientation of panels is by column. If you want to change this to sort of row, you can do so by adding this to your script:

group02.orientation = "row";
Copy after login

Text

There are likely 2 types of text you would want to include in your script: static text, and editable text.

Static Text
Static text can be used for instructions to the end user. Add "statictext"to your object like so:

//New Window
var mainWindow = new Window("palette", "Title", undefined);
Copy after login
Copy after login
Copy after login

Again we use the add control object, with the same type, bounds, and text arguments.

Editable Text
Editable text provides a text box field for the end user to type into. This is useful if our script requires information from the end user, like customizable text layers. Add "edittext" to your object like so:

mainWindow.show();
Copy after login
Copy after login

This is simply a different type of object. The text we provide in the text argument will initially be inside the text box, ready for the end user to delete and write their own text inside.

Screenshot of script displaying a static text and editable text example.

As you can see, with the size of the boxes undefined, the text in the editable box is slightly cut off. We can fix this by defining the size after the fact:

group01 = mainWindow.add("group", undefined, "Group 01");
Copy after login
Copy after login

This allows us to make the textbox size adaptable later, if we so choose.

Screenshot of script displaying a static text and editable text example,with a slightly bigger text box.


Buttons

It is also likely you will need buttons for your script, at the very least to give the end user an option to "run" the script.

Adding a button is a similar process:

group01.orientation = "column";
Copy after login
Copy after login

This creates our button.

Screenshot of a script with a run button.

However, for our button to do anything, we will need to tell our script what to do when our button is pressed. I like to create a function to house all the tasks I want the button to complete.

group02 = mainWindow.add("panel", undefined, "Group 02");
Copy after login
Copy after login

Here, we use button01.onClick to run our first function, where we ask it to run app.beginUndoGroup("Tutorial") so that undoing the script is a single action from inside After Effects. Next, we tell it to run our function completeTasks. Underneath, I define the function completeTasks. Here, include all the actions you want your button to complete (for now, mine only closes the script window), and finish the function by adding app.endUndoGroup("Tutorial") to close the undo group.

I'll be going into more detail about this in a future article.


Options

Other options for control objects available are located on the Javascript Tools Guide CC

Objects such as checkboxes, dropdown menus, radio buttons, and sliders are covered here, to name a few, and follow similar procedures to adding text or buttons.


Example

Let's connect what we've learned about windows to the previous article, and make an example script which creates and opens a new composition.

//New Window
var mainWindow = new Window("palette", "Title", undefined);
Copy after login
Copy after login
Copy after login

Let's go through this script.

I start off by creating my window and my groups. Group01 is my "panel", adding the heading "description" to the static text. Meanwhile the rest of my objects go inside Group02, a "group" object. Since I want the orientation of Group02 to be a column, I set that here.

Then, I create my objects. I start with my statictext inside of Group01. Next, I create 2 edittext objects inside of Group02, for the user to specify the size of the new composition they want to create, and I specify the size of both those text fields. Lastly, I create a button so that the script can be run by the end user.

Once I have created all my variables, I create my functions. I first set my onClick function for my button as explained, by opening the undo group and running the custom function completeTasks.

I then define completeTasks. First, I need to use parseInt() on the text of both compWidth and compHeight edit text objects. This converts them from text to integers, so that the rest of the script can understand the inputs. Once this is done, I create a new composition, setting the width and height to the values inputted by the user. The composition is then opened and becomes the active comp, before the script window closes, and the undo loop is closed.

Running this script allows you to make a new composition set to the width and height values specified in the text fields.

This script can be improved by adding an alarm, should anything be added to the text fields that isn't an integer (or perhaps setting a maximum value), to warn the user that the script has failed. This is something I will go over in more detail in another article. For now, if there is an illegal character in the text field, the script will simply not work until both the width and height text fields have numbers typed into them.

Screenshot of completed script


Conclusion

This concludes the beginners guide to creating windows for After Effects scripts using Adobe Extendscript Toolkit CC. Next article I will cover creating different types of layers for your compositions.

The above is the detailed content of Scripting: Creating Windows For Your After Effects Scripts. 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
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
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