Ep. 05 collectAllPrecomps Free Function Friday
Welcome to this weeks episode of Free Function Friday. Today we will build a function to collect all of the precomp objects in a project. The difference between a precomp and a composition, if you are unaware, is that a precomp is a composition that resides within another composition as a layer. Precomps are a handy way of organizing your layers as you create, and in some cases it is required to perform a certain effect or process. When scripting there may be the need to know which compositions are being used within another composition. One such case is if you are organizing your project into folders via script, as I did in this older post for Organizing Project Assets. I used a slight variant of the collectAllPrecomps function in that script to first gather them and then looped through those results and set their parent folder to the same location. This function was also altered and used in different variations to also gather other types of project items to sort them as well.
Since you will have a collection of CompItems after running the function, you could then send those comps through a loop and read and/or write any of the attributes related to a CompItem object. Those attributes as of After Effects CC 2015 would be…
frameDuration: The duration of a single frame. |
dropFrame: When true, indicates that the composition uses drop-frame timecode. |
workAreaStart: The work area start time. |
workAreaDuration: The work area duration. |
numLayers: The number of layers in the composition. |
hideShyLayers: When true, shy layers are visible in the Timeline panel. |
motionBlur: When true, motion blur is enabled for this composition. |
draft3d: When true, Draft 3D mode is enabled for the Composition panel. |
frameBlending: When true, time filtering is enabled for this composition. |
preserveNestedFrameRate: When true, the frame rate of nested compositions is preserved. |
preserveNestedResolution: When true, the resolution of nested compositions is preserved. |
bgColor: The background color of the composition. |
activeCamera: The current active camera layer. |
displayStartTime: Changes the display of the start time in the Timeline panel. |
resolutionFactor: The factor by which the x and y resolution of the Composition panel is downsampled. |
shutterAngle: The camera shutter angle. |
shutterPhase: The camera shutter phase. |
motionBlurSamplesPerFrame: The minimum number of motion blur samples per frame for Classic 3D layers, shape layers, and certain effects. |
motionBlurAdaptiveSampleLimit: The maximum number of motion blur samples of 2D layer motion. |
layers: The layers of the composition. |
selectedLayers: The selected layers of the composition. |
selectedProperties: The selected properties of the composition. |
renderer: The rendering plug-in module to be used to render this composition. |
renderers: The set of available rendering plug-in modules. |
duplicate(): Creates and returns a duplicate of this composition. |
layer(): Gets a layer from this composition. |
openInViewer(): Opens the composition in a Composition panel. |
So you can quickly start to see how you could easily set all precomp frame rates, or change precomp sizes, even set the precomp workarea start and end. There are lots of possibilities.
If you haven’t done so already there is a Free Function Friday introduction video located here that has some important information pointing to a few resources that will come in handy when scripting for After Effects.
Episode 5 collectAllPrecomps:
Legal note: The Adobe ExtendScript code talked about in this article and accompanying embedded video(s), and/or graphic images are not guaranteed to be compatible with every version of After Effects. David Torno, ProVideo Coalition, and Diversified will not be held liable for any misuse or incorrect use of the provided ExtendScript code. Use at your own risk.
All of the code I provide in this series, has been created and tested in After Effects CC 2014. Unless otherwise specified in the episode, the code should be compatible with After Effects CS6 through CC 2015. I’ve done my best to avoid depreciated code (code that Adobe removed at some point), and made these functions as compatible as possible. There will however be the occasional piece of code that is brand new as of a certain version of After Effects and therefore will not be backwards compatible from that version. I will mention these if that is the case.
With that said, all the code I provide in this series is open source and free to use in your scripts. I highly encourage you to expand and improve upon the code I provide and start making your own custom functions as well, but please do not repost the code I show in this series as is and claim it as your own. If you use any of the code provided in this series please give credit where credit is due. This series is meant to provide, what I feel is useful code, as well as to hopefully further explain ExtendScript and it’s quirks. While the functions we build throughout this series can perform a task all on their own, they are not meant to be a solo script. How you combine them together and expand upon them is when you will gain the most from these functions.