Expression Basics

Native Attributes

In the Referencing Layers and Compositions article you learnt how to create references to After Effects compositions and layers in your expressions, as well as their attributes such as their position, opacity, and scale.

You also learnt, from the previous article about objects, that compositions and layers are JavaScript objects, with the layer attributes being properties of those objects.

These objects also have other properties you can access in expressions, which you're unable able to pick whip to as they don't appear in the timeline.

Native attributes are the properties on After Effect's built in objects, such as compositions and layers.

In this article you'll learn how to find and use these native attributes built into After Effects.

Finding and using attributes

The expression language menu

The easiest way to find what attributes are available is via the expression language menu, which is the small arrow next to the pick whip on an property with an expression.

The expression language menu

Clicking on the arrow reveals the objects available, with their attributes listed as the items in each sub menu. Selecting one of the attributes will insert it into the expression.

The expression language menu is a way of seeing the native attributes available, and inserting them into your expression.

Below is an example of using the expression language menu to insert a reference to the composition duration (duration) which you can find under the "Comp" sub menu.

As you can see, inserting the duration property alone results in an error:

js
duration;
js
Reference Error: duration is not defined

This is because duration is a property of a composition object, which you can tell as it's found under the "Comp" menu.

As you learnt in the previous article, property references must always begin with their parent object.

Changing the expression to reference the duration of the current composition object (thisComp) solves the error, and returns the correct duration.

js
thisComp.duration;
js
180;

You can know which object to reference by it's location in the expression language menu, whether it's an attribute of a composition, layer or property. For example, speed is an attribute of Properties as it's found under the "Property" menu.

To learn more about how to reference layers and compositions, see Referencing Layers and Compositions.

The expression language reference

You can also find a list of most of the native attributes available on Adobe's website, as well as explanations on each attribute.

Expression language reference (Adobe)

This page is a vital resource for writing expressions, and is worth reading and keeping bookmarked.

Layer and property object references

You may have noticed that for attributes of layer and property objects, such as thisLayer.inPoint and thisProperty.numKeys, you can omit the object reference without causing an error.

js
// With object reference
thisLayer.inPoint;
// Without object reference
inPoint;
js
2;

This seems to contradict what you learnt about objects: that you must always reference the parent object before the attribute (parentObject.attribute).

Expression pre processing

The reason layer and property attributes work without the object reference is that After Effects pre-processes expressions to add references to the current layer or property object on native attributes.

js
// Un processed (invalid) expression
inPoint;
numKeys;
// Processed (valid) expression
thisLayer.inPoint;
thisProperty.numKeys;

For a more in depth look at expressions pre-processing, see the article: What happens during expression pre-processing

This pre processing is not done to code in external .jsx files, so you must ensure to add the object references yourself in that case.

Whether you add the property references yourself, or let After Effects add them during pre processing, is a matter of preference.

For the sake of being explicit about what objects the attributes belong to, we prefer to add object references in our own expressions.

Commonly used attributes

Below is a list of native attributes most commonly used in expressions, grouped by their parent object. Knowing when and how to use these attributes is a key part of writing expressions.

Composition

Attributes on composition objects, such as thisComp or comp("Lower Third"), include:

  • name: The name of the composition
  • width: The width of the composition in pixels
  • height: The height of the composition in pixels
  • duration: The duration of the composition in seconds
  • numLayers: The number of layers in the composition

Layer

Attributes on layer objects, such as thisLayer or thisComp.layer("Name"), include:

  • index: The position of the layer in the layer stack
  • inPoint: The start point of the layer in seconds
  • outPoint: The out point of the layer in seconds
  • parent: The layer object of the layers parent
  • width: The width of the layer in pixels
  • height: The height of the layer in pixels

Property

Attributes on property objects, such as thisProperty or thisLayer.transform.opacity, include:

  • numKeys: The number of keyframes on the property
  • value: The current value of the property
  • velocity: The current velocity of the property
  • speed: The current speed of the property
  • name: The name of the property (e.g. "Opacity")

Wrapping up

Native attributes enable you to use properties of layers and compositions in your expression, such as their size and duration. Knowing how to find and use these attributes is a key part of writing expressions.

There are also functions built into these objects, known as native methods, which you will learn more about in a future article.

For enquiries contact us at hey@motiondeveloper.com