(Page 1 of 2 pages for this article 1 2 >)
Saturday, May 01, 2010
Deeper Modes of Expression, Part 5: Comp, Footage, and Layer Attributes
Chris Meyer | 05/01
Grabbing numbers from places such as the comp settings.
If you can keyframe it, chances are you can control it with an expression, or use it as part of another property’s expression – usually by dragging the pick whip to it. However, there are additional properties you have access to – including those you can’t access with a pick whip, such as whether a layer’s audio or video switches are on, or its current in or out point. You’ll need to either manually type in code to access these, or get some help from the expression language menu. To give you a taste for what’s possible, let’s discuss a couple of comp and footage attributes of interest.
Expressions can access a large number of composition attributes, including the width and height of the comp, the comp’s duration, the duration of a single frame at the comp’s current frame rate, and the comp’s pixel aspect ratio. This saves you from having to calculate or transcribe these numbers by hand; expressions that use these properties will also automatically update as you change a comp’s settings (such as its frame rate). It also makes expressions easier to reuse, as they can automatically refer to a comp or layer’s properties, rather than requiring you to edit the expressions to match a new comp or layer size or frame rate.
Let’s say we want to arrange a series of layers in a line from the upper left corner of a comp to the lower right corner - regardless of the size of the comp:

The upper left corner is easy; it’s value is always 0, 0. We could enter this as its value, but when you resize a comp, the Position values of layers can change. Therefore, to nail it down to that corner, we can enter the expression [0, 0] for the first layer’s Position. (As you know by now, Position for a 2D layer has two dimensions, so we need to give it two values - one for each dimension - inside brackets, separated by commas.)
To place an object in the lower right corner, we need to know the comp’s dimensions. To dig out that piece of information, we would apply the following expression to that layer’s Position:
[thisComp.width, thisComp.height]
Note that if we did not type thisComp. before width, After Effects would have assumed we wanted the layer’s width, not the comp’s width.
It follows that the expression to place an object in the center of a comp is [thisComp.width/2, thisComp.height/2]. And placing objects in between the center and the corners is just a matter of dividing the comp into quarters: [thisComp.width/4, thisComp.height/4] and [thisComp.width * (3/4), thisComp.height * (3/4)]. The resulting timeline panel would look like this (remember, you can select layers and press U to reveal any animating properties be they controlled by keyframes or expressions; type EE to see just the properties with expressions attached):
The advantage of using expressions like these is that we can change the comp’s size (maybe because the client neglected to give us the correct deliverable size before we started), and the objects will automatically redistribute themselves correctly with no intervention on our part:
(By the way, one of the small but useful features added in AE CS5 is that many dialogs - such as Composition Settings - have Live Preview switches, meaning you get to see the impact of your changes before you close the dialog. This is particularly handy for editing motion blur settings. But I digress…)
You can use the expression language menu to cut down on typing expressions such as these, but you will need to do it in three steps after you have enabled expressions:
Step 1: Select Global > thisComp
Step 2: Type a period (.)
Step 3: Select Comp > width (or whatever property you want)
It is up to you to decide if that’s easier than just typing thisComp.width – but if nothing else, the expression language menu reminds you of what’s available, and what the correct syntax (spelling) is.
next page: converting between frames and seconds
(Page 1 of 2 pages for this article 1 2 >)
You must be registered to comment. This is an effort to reduce spam. Please REGISTER HERE.
WOW! Cool topic and cool article, very well written.
Posted by .(JavaScript must be enabled to view this email address) on 05/03 at 05:51 AM
|