Understanding the sourceRectAtTime() Expression in After Effects

The sourceRectAtTime() is a powerful expression in Adobe After Effects that you can use to dynamically measure the dimensions of a layer. It returns the dimensions of the layer’s bounding box at a given time, in the form of a rectangle structure with lefttopwidth, and height properties.

Here’s a basic usage example:

let myLayer = thisComp.layer("My Layer");
let myLayerBounds = myLayer.sourceRectAtTime();

In this example, myLayerBounds now contains the dimensions of “My Layer” at the current time. You can access the properties like so: myLayerBounds.widthmyLayerBounds.height, etc.

One common use of sourceRectAtTime() is to create a background that automatically adjusts its size to the text layer. Here’s how you can do it:

let textLayer = thisComp.layer("My Text Layer");
let padding = 10; // Add 10 pixels of padding
let bounds = textLayer.sourceRectAtTime();
[thisComp.width, bounds.height + padding * 2];

In this example, the expression is applied to the Scale property of a shape layer. The shape layer will automatically adjust its height according to the text layer’s height, with an additional padding of 10 pixels.

Remember, sourceRectAtTime() can be extremely useful for creating flexible, dynamic layouts in After Effects. Happy animating!

Resources for deeper understanding of SourceRectArTime expression.

Leave a Reply

Your email address will not be published. Required fields are marked *