CHAPTER 10

image

Expressions, Scripting, and Project Management

Visual effects composites can become complex, making them difficult to edit, update, and complete. Fortunately, there are numerous ways to simplify and optimize your workflow in After Effects. For example, expressions allow you to automate property animation and therefore save time when keyframing (Figure 10.1). JavaScript support opens the program to a wide range of scripting tools to make your compositing more efficient. In addition, the program provides many options for adjusting element names, memory management, and interface layout. If you have access to multiple computers with an After Effects installation, you can set up your own After Effects render farm.

This chapter includes the following critical information:

Creating and editing expressions

Running JavaScript scripts

Running an After Effects render farm

image

FIG  10.1 An After Effects expression. This is demonstrated in the “Creating an Expression Mini-Tutorial” later in this chapter.

Automating with Expressions

Expressions allow you to automate properties within After Effects. That is, you can have the values of one property transferred automatically to another property. The contributing property (which I’ll refer to as the driver) and the affected property (the driven) can exist on the same layer or can be located on two different layers. The properties can be identical (for example, X Position on layer 1 and X Position on layer 2) or dissimilar (Position X on layer 1 and Anchor Point X on Layer 2).

The ability to link properties via expressions prevents or reduces the need for keyframe animation. In addition, you can create complex mathematical equations that relate two properties. This comes in handy when trying to create complex animation that may not be intuitive.

Creating an Expression

To create a simple expression, follow these steps:

1. Identify the two properties you’d like to link through an expression. They can be on the same layer or different layers. Expand the Transform section or sections to reveal the property names in the layer outline.

2. Select the property that is to be driven. Choose Animation > Add Expression from the main menu. An Expression section is added below the property name. A partial expression is added to an expression field in the timeline area to the right of the expression section.

3. Click the Pick Whip button in the new expression section. While continuing to hold down the LMB, drag the Pick Whip rubber band line to the driver property name. A gray box appears around valid property names. Release the mouse button. An expression is created and the expression line is updated (Figure 10.2). To finish the expression, click in an empty area of the timeline.

image

FIG  10.2 An expression is added to the Position property of a solid layer named Solid 1. The Position property of a second solid layer, named Solid 2, serves as the driver. The Pick Whip button is outlined in yellow.

4. As a test, alter the driver property values. The driven property values update automatically to match. These transform changes are visible in the Composition view.

Note that the expressions are sensitive to property channels. For example, the Position property has two channels: X and Y. The Scale property has two channels: X and Y. Opacity, on the other hand, has a single channel, simply named Opacity. When creating an expression, you can connect the following combinations of channels:

Single-channel to a single-channel

Two-channel to a two-channel

Single-channel to one channel of a two-channel property

One channel of a two-channel property to one channel of a two-channel property

When using the Pick Whip tool, you can make two-channel connections by placing the Pick Whip rubber band line over the property name (such as Anchor Point or Position). When making a single-channel connection, you can place the line over the property name or the property value field. In order to make a connection to one channel of a two-channel property, place the line over the property value field (such as the X Position field).

When working with a 3D layer, a third channel, Z, is added. As such, you can connect three-channel properties to three-channel properties or single-channel components to each other. Note that you’re not limited to transforms but can connect any animatable property as part of an expression, including those included with effects.

To remove an expression, select the property that carries the expression in the layer outline and choose Animation > Remove Expression.

Expression Channel Syntax

When you create an expression, it’s represented by a piece of programming code in the expression field. Driver properties are listed in the expression field with the following syntax:

composition.layer(“layer”).class.channel

If the driver property exists on the same layer, you can simplify the reference:

class.channel

You can think of the class component as the section within which the property appears. For example, the two-channel Scale property is written as transform.scale. If a single channel of Scale is used as a driver, the specific channel is listed. Hence, Scale X is written as transform.scale[0]. In this situation, the number within the [ ] represents an array position, where [0] is the X channel, [1] is the Y channel, and [2] is the Z channel (if it exists). The Position property is the exception to this rule as its channels are separable with the Separate Dimensions option. As such, X Position is listed as xPosition, Y Position is listed as yPosition, and so on.

When creating an expression with an effects property, the following format is used:

effect(“effect name”)(“property”)

Writing Expressions

You can manually update a preexisting expression by clicking in the expression field and proceeding to type. To finalize the update, click off the expression in an empty part of the timeline. If the expression becomes invalid due to improper syntax or incorrect layer/property naming, a warning dialog opens and the expression is disabled. You are free to update an expression at any time.

You can also write an expression from scratch and thus avoid using the Pick Whip tool. To do this, select the driven property in the layer outline and choose Animation > Add Expression. The expression field is added with the channel name listed. You can type directly into the field to finish the expression. In this case, you must use an = sign to indicate to what the driven property is equal. You must include the driver property to the right of the = sign. For example, if you want to write an expression that links Position to Anchor Point on a layer, you can write:

transform.position = transform.anchorPoint

With this syntax, the driven property is always listed on the left. In words, the right-hand property supplies values to the left-hand property. If you are linking properties that exist on two different layers, you must add the layer name:

transform.position = thisComp.layer(“layer2”) .transform.anchorPoint

With this example, layer2 carries the driver property. thisComp refers to the current composition, although you can replace this with a specific composition name with the following syntax:

transform.position = comp(“Comp 1”).layer(“layer2”).transform.anchorPoint

You can refer to a layer through its index (the layer number listed beside the layer name in the layer outline). For example, you can write layer(2) for layer number 2 in the layer outline.

You are not limited to making a one-to-one correlation between properties. You can use mathematical formulas to make the relationship asymmetrical. For example, to make the driven property increase at a rate that is twice as fast as the driver property, include *2 at the end of the expression line. The * symbol represents multiplication. Other math operators include:

/ divide
+ plus
minus
^ power function

You can invert a resulting expression value (positive to negative or negative to positive) by including *−1 at the end of the expression line.

You can place the mathematical formulas within parentheses to order the operations. You can also use multiple property names as part of the formula. As a more complex example, two properties are used in the following expression:

transform.xPosition = transform.yPosition* ((2/transform.zPosition)−3)

This expression carries out the calculation in the following order with innermost parentheses sets taking precedence over outer parentheses sets:

1. 2 / transform.zPosition

2. [Step 1] − 3

3. transform.yPosition * [Step 2]

The expression field supports multiline expressions. Each line must end with a semicolon. You can expand the size of the expression field by LMB-dragging the line directly below the field in the timeline area. Expressions support the use of variables. These may be necessary to pass different values to properties with multiple channels. You can think of variables as temporary “buckets” that carry and pass changing values. A multiline expression that uses variables is demonstrated in the “Creating an Expression Mini-Tutorial” later in this chapter.

Additional Expression Options

When you add an expression to a property, several buttons are added in addition to the Pick Whip tool. For example, you can temporarily turn off an expression by clicking off the Enable Expression switch (Figure 10.3).

You can view the animation curves of the driver property by clicking the Include This Property button and switching to the Graph Editor view in the timeline area. The expression itself is represented by one or more flat-line curves—these are for reference and aren’t designed for alteration. However, you can edit the driver property curves.

image

FIG  10.3 Left to right: Enable Expression, Include This Property, Pick Whip, and Function buttons.

You can “freeze” an expression by converting it into keyframes. To do so, select the property that carries the expression, and choose Animation > Keyframe Assistant > Convert Expression To Keyframes. The property receives a keyframe for each frame of the timeline that carry values previously passed to the property via the expression. The Expression switch is automatically toggled to off. Note that an expression trumps keyframes if both a keyframe animation and an active expression exist for a property.

You can incorporate a long list of mathematical functions and internal After Effects functions by RMB-clicking the Function button (Figure 10.2). For example, you can insert a randomly generated value into the expression by following these steps:

1. Prepare to edit the expression by clicking on the expression field in the timeline. A blinking cursor indicates where a new type will appear. If necessary, add a mathematical operator, such as +.

2. RMB-click the Function menu, and choose Random Numbers > Random(). The phrase random() is added to the expression. Like many functions, random() requires a value between the ( ) to become operational. For example, if you place 100 within the parentheses, a random value between 0 and 100 is randomly generated with each frame. This offers a means to create random jiggle, wiggle, rotation, scale fluctuation, and so on.

3. Click off the expression field to update the expression.

After Effects functions provide a means to alter qualities and properties outside standard transforms. For example, you can alter properties of cameras, values of keyframes, resolution of footage, background color of compositions, and so on. For a more thorough examination of the available functions and examples of their use, see the “Expression Language Reference” pages of the online After Effects Help center (helpx.adobe.com/after-effects/topics.html).

Automating Animation with Expressions

At times, keyframe animation can become tedious. Hence, you can use expressions to simplify the animation process.The following tutorial steps you through one such scenario.

Creating an expression mini-tutorial

In this tutorial, we’ll add “stretch and squash” animation to a bouncing ball project with the addition of an expression. You can follow these steps:

1. Open the expression_start.aep project file included in the ProjectFilesaeFilesChapter10 directory. Play back the timeline. This features a motion graphic animation of a ball bouncing. The ball and ground are constructed from two solid layers. The ball layer has its Position property keyframed (Figure 10.4).

image

FIG  10.4 A bouncing ball animation is created by animating the Position of a solid layer cut out with a circular mask.

2. Select the Scale property of the Ball layer in the layer outline and choose Animation > Add Expression. The expression is added and the expression field is opened. Click within the field to begin typing. Use the backspace key to remove the initial expression. Type the following:

xScale = 100;

yScale = (1/transform.position[1])*40000;

[xScale, yScale]

3. Refer to Figure 10.1 at the start of this chapter. To jump to a new line, press the Enter key. If you accidentally leave the expression field, you can return to it at any time by clicking within the field. When the expression is entered correctly and you leave the expression field, the expression is activated. (If an error dialog appears, return to the field and correct the errors; errors may occur through misspelling and similar typing mistakes.) Play back the timeline. The ball stretches when it appears high off the ground. When the ball is close to the ground, it squishes (Figure 10.5).

image

FIG  10.5 Left to right: Frames 1, 5, and 8 after the addition of the expression. The “squash and stretch” animation occurs by relating Scale Y to the Y Position. With this example, motion blur is activated. The Rotation property is also keyframed.

4. Optionally, animate the Rotation value for the ball layer so that the angle of the stretching or squashing matches the motion path and the direction the ball is traveling. Optionally, activate motion blur for the ball layer.

With this expression, the Scale X property is given a static value of 100 percent. The value of 100 is assigned to the variable xScale. The Scale Y property, on the other hand, is driven by the ball layer’s Y Position. The Y Position is called with an index: position[1]. The Y Position value is stored by the yScale variable. The xScale and yScale variable values are passed to the Scale X and Scale Y properties via the last line of the expression. Placing two variables within the [ ] is necessary when using a handwritten expression on a double-channel property, such as Scale.

The expression is not a one-to-one relationship. The ball layer’s Y Position varies from approximately 180 (in air) to 498 (near ground). In order to reduce the value sizes to make them more suitable for a scaling operation, 1.0 is divided by the Y Position. For example, 1/180 = 0.0055. This also has the effect of making higher Y Position values produce larger numbers while lower Y Position values produce smaller numbers (0, 0 in After Effects screen space is at the upper left of the frame). Hence, 1/498 = 0.002. This causes the ball to become shorter when approaching the virtual ground. In order to make the values somewhere between 0 and 100, the result is multiplied by 40,000. Hence, (1/180)*40,000 = 222.22. You can change the 40,000 to other values to produce a lesser or greater degree of squashing and stretching. A completed version of the project is included as expression_finished.aep in the ProjectFilesaeFilesChapter10 tutorial directory.

Running JavaScript Scripts

After Effect supports advanced scripting through JavaScript. (A script is a sequence of written instructions that is carried out by a program, such as After Effects, instead of the computer processor.) Such scripts are capable of creating complex automation that incorporates program functionality, custom graphic interface components, such as window and dialog boxes, and file importation and exportation. While it is far beyond the scope of this book to cover the intricacies of JavaScript scripting, it’s worth covering the installation and running of such scripts. Numerous JavaScript scripts are available to After Effects users. They cover a wide range of tasks, including the creation of custom cameras, the creation of specialized motion graphic effects, and the semi-automation of motion tracking, green screen removal, keyframe animation, and rotoscoping. Many of these scripts are available at such websites as aescripts.com and aenhancers.com.

To run a JavaScript script, choose File > Scripts > Run Script File and choose a JavaScript script. The scripts are text files with the .jsx extension. Some scripts will immediately launch a custom window and await user input. Other scripts will run in the background to achieve a particular task. In general, scripts available outside of After Effects include some type of documentation that explains the scripts’ functionality. This might come in the form of pop-up dialogs that appear as the script runs or comments within the script text itself. You can examine the script text by choosing File > Scripts > Open Script Editor and then choosing File > Open through the Editor window. In JavaScript, comments are surrounded by /* */ symbols or appear on lines starting with // (Figure 10.6).

image

FIG  10.6 A small portion of a script, as seen in the Script Editor. Comments are highlighted in green.

You can install scripts so that After Effects recognizes them automatically. To do so, copy the .jsx file, along with any associated bitmap images (sometimes included for custom graphic interface components or special effects), to the ScriptsUI Panels directory. The directory paths follow:

Mac: ~ApplicationsAdobe After Effects versionScriptsScriptUI Panels

Windows: C:Program FilesAdobeAdobe After Effects versionSupport FilesScriptsScriptUI Panels

After Effects lists any scripts located in the ScriptsUI Panels directory at the bottom of the Window menu. As a bonus, After Effects includes its own small set of example scripts as part of the program install. You can access these by choosing File > Scripts > script name. These scripts are located in the program’s Scripts directory. If you place your own scripts within this directory, they will be listed in the same menu.

Project Management

Visual effects projects undertaken in After Effects can become confusingly complex due to a large number of layers, effects, and animated properties. Hence, it’s often necessary to spend time organizing all the components to make the workflow manageable. These steps include layer renaming, memory management, and customization of the program environment. Optionally, you can spread After Effects render queues across multiple computers as part of a render farm.

Renaming Layers

You can rename layers by RMB-clicking a layer name in the layer outline, choosing Rename, and entering the new name into the field that appears. This is useful for organizing a complex, multilayer composition. Layer names do not affect the layer source names. In fact, you can toggle between the layer name and the source name by clicking the top of the name column in the layer outline. You are also free to rename a composition at any time by selecting the composition tab in the timeline or composition name in the Project panel and choosing Composition > Composition Settings.

Managing Memory

When you play back the timeline, After Effects writes out temporary files to a disc cache. With a large or complex project, a significant amount of space can be used and the operating system efficiency may be affected. Hence, it sometimes is beneficial to purge the cache. You can do this by choosing Edit > Purge > All Memory & Disc Cache. The location of the disc cache is set by the Media & Disc Cache section of the Preferences window (found through the Edit menu). You can also set the disc cache size, in gigabytes, here. You can set the usage of system RAM memory through the Memory page of the Preferences window.

If a project is utilizing an unacceptably large portion of RAM memory or is rapidly filling the disc cache, consider the following steps to make the project more efficient.

Using Reduced Quality

While testing and adjusting a project, view the composition with reduced quality. Set the Resolution/Down Sample Factor Pop Up menu (Figure 10.7) to Half, Third, or Quarter. Each of these settings skips pixels. Thereby, calculations involving layer blending and effects application are more efficient and smaller temporary image files are written to the disc cache.

image

FIG  10.7 The Resolution/Down Sample Factor Pop Up menu (red), Region Of Interest button (green), and Fast Previews menu (blue), as seen at the bottom of the Composition view panel.

Fast Preview

When you transform a layer or alter effect properties, every pixel within the frame is updated. With complex compositions, there can be a lag between the update of the property values and the display of the image in the view. You can reduce this lag by switching the Fast Previews menu (Figure 10.7) from Off (Final Quality) to Fast Preview. With this setting, only 1/4 of the pixels are displayed while the property values are changing. This is particularly useful when interactively transforming the layer or moving an effect slider back and forth in real time. You can also set the menu to Wireframe. With this setting, only a wireframe bounding box is displayed for each layer. This is useful for quickly positioning, rotating, or scaling a layer. If you are using the Ray-Traced 3D renderer, you can set the Fast Previews menu to Draft, which reduces the number of rays traced to the minimum of 1.0, or Adaptive Resolution, which adaptively reduces the pixels based on current memory demands. For more information on the Ray-Traced 3D renderer, see Chapter 5.

Testing Regions

By default, the Composition view shows the entire frame. However, you can preview smaller areas and therefore reduce calculation times by clicking the Region Of Interest button (Figure 10.7) and drawing a region box in the view. Areas outside the box are ignored until the region is disabled by clicking the Region Of Interest button off.

Pre-Rendering

Render a portion of the project to disc and re-import it as an image sequence. For example, render Comp 1 and re-import it. All the layers and effects used for Comp 1 are thereby flattened into a single, new layer. This reduces memory usage as Comp 1 becomes an imported series of images and no processor time is used to combine the old Comp 1 layers or apply a series of effects. After Effects provides a means to do this by including Composition > Pre-Render. Pre-Render loads the current composition into the render queue. At the same time, Pre-Render automatically sets the Post-Render Action menu, in the Output Module Settings window, to Import & Replace Usage. This causes the program to replace the prior contents of the composition with the newly rendered sequence. Before undertaking this process, save a copy of the project that contains the original composition with all the intact layers and effect settings.

Reducing Resolution

If your intended output resolution is smaller than your source footage, reduce the footage resolution before working with it. For example, if the source footage is 1920x1080, yet your output resolution only need be 1280x720, reduce the footage to 1280x720. You can create a temporary After Effects project to reduce the footage resolution. With this example, you can create a 1280x720 composition, drop the 1920x1080 footage into the composition with a Scale of 67 percent, and render the composition through the render queue.

Customizing the Program Environment and Keyboard Shortcuts

You can rearrange panels at any time. (Panels are listed in the Window menu and appear with named tabs within the various program frames.) To move a panel to a new location, LMB-drag the panel’s named tab into a different frame. When you do so, a ghosted box appears within the new frame. Release the mouse button to drop the panel into the new frame. You can also undock a panel so that it floats free. To do so, RMB-click the window tab name and choose Undock Panel.

You can save the current program workspace, with its current panel and frame arrangements, by choosing Window > Workspace > New Workspace. Name the workspace in the New Workspace window. The workspace is then listed in the Window > Workspace menu. You can switch to a different workspace at any time by choosing Window > Workspace > workspace name. You can return to the factory workspace by choosing Window > Workspace > Reset “Standard”. The program provides additional workspaces designed for particular tasks in the same menu (e.g. Animation, Motion Tracking).

After Effects includes a large number of keyboard shortcuts. These are stored in a text file, which you can review or alter. To locate this file, choose Edit > Preferences > General. Click the Reveal Preferences In Explorer (Windows) or Reveal Preferences In Finder (Mac OS X) button. An external directory window opens, revealing the en_US Shortcuts.txt or similar language-specific text file. You can alter this file in a text-editing program. The keyboard shortcuts follow the syntax operation” = “(key combination)”. For example, the shortcut for creating a new project is “New” = “(Ctrl + Alt + N)”.

Using Built-In Render Farm Support

After Effects comes with built-in render farm support. A render farm is a collection of computers that are able to split a render queue. For example, computer 1 might render frames 1 to 50 while computer 2 renders frames 51 to 100. Render farms reduce overall render times and are commonly used by animation, visual effects, and motion graphic studios. To utilize this support, you must have the following:

Two or more computers with the same valid version of After Effects and any required plug-ins installed

A network drive that stores shared project files that is accessible by all the render farm computers

If these components are available, you can follow these basic steps to set up an After Effects project that is ready to render on a multicomputer render farm:

1. On the shared network drive, create a directory named _WatchFolder. You can locate this directory anywhere on the drive.

2. Open the After Effects project that you would like to place on the render farm. Add the project to the render queue by selecting the appropriate composition and choosing Composition > Add To Render Queue. In the Render Queue tab, click Best Settings. In the Render Settings window, select Skip Existing Files in the Options section. Close the window.

3. Set the options within the Output Module (e.g. file type, audio). Choose a file name and location through Output To. Choose a location on the network drive so that all machines on the render farm render to a shared directory (this prevents the farm computers from rendering identical frames).

4. Save the project to the _WatchFolder on the network drive.

5. Choose File > Dependencies > Collect Files. In the Collect Files window, set the Collect Source Files menu to None (Project only). Select the Enable ‘Watch Folder’ Render check box (Figure 10.8). Set the Maximum Number Of Machines to the number of farm computers you’d like to use. Click the Collect button to close the window.

image

FIG  10.8 The Collect Files window.

6. Go to each render farm computer, launch After Effects, and choose File > Watch Folder. A file browser window opens. Navigate to the _WatchFolder directory on the network drive and click the Choose button. The Watch Folder window opens and After Effects actively scans the selected directory (Figure 10.9). When a farm computer detects an After Effects project file, it opens the file and begins to render the render queue. To cancel the watch for a particular farm computer, click the Cancel button in the Watch Folder window for that computer. (At the time of this writing, File > Watch Folder was disabled for After Effects CC 2015; however, CC 2014 is able to render CC 2015 Watch Folder projects.)

image

FIG  10.9 The Watch Folder window between _WatchFolder directory scans.

Book Wrap-Up

After Effects is a deep program with a seemingly inexhaustible number of menus, options, and effects. Hence, I’ve intentionally concentrated on those components within the program that have proven to be the most useful with my own visual effects experience (which spans close to three decades). That said, there is no single way to tackle a particular visual effects task. In fact, the more you composite, the more flexible you’ll become and the more likely you’ll develop your own techniques—and there’s the beauty of the art form. Whatever the path, have fun and thank you for reading this book!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset