SourceRectAtTime ( )

After Effects SourceRectAtTime Expression

This expression allows shape layers to automatically resizing to a text layer. Great for lower-thirds! Intermediate skill level for coding. Video tutorial I would recommend watching Evan Abrams video of SourceRecAtTime ( ) and Jake in Motion SourceRectAtTime.

Let’s Get Started:

  1. Step One: Create a Rectangle layer in a new composition. You can just double click the rectangle tool next to the Pen tool, in the Tools Panel.
  2. Step Two: Then create a Text Layer with copy. We will name this layer “Text”.
  3. Step Three: Adjust the Text Layer Anchor points so the text is always aligned to the center, no matter the text paragraph alignment. Open the text layer and inside of the Transform Property Group open > Anchor Point and click on the stop watch icon to start writing the expression:
    • Create a Variable we will name it “s“, the = sign. Grab the pick whip to the text layer, and add the .sourceRectAtTime() after the code. It should look like this s=thisLayer.sourceRectAtTime();
    • Create Variables for all the attributes, Height, Width, Top, Left.
      • Height = s.height;
        • This would read. For Variable Height find the height property s.height; in Variable s, which is the current layer.
      • Width = s.width;
      • Top = s.top;
      • Left = s.left;
  4. Add Variable x . Make the sum of X is equal to the full width of this layer, plus the left attribute and dividing it by 2; thus getting the horizontal center.
    • x = Left + Width/2;
  5. Do the same with Variable Y, except use the Height and Top for its sum.
    • y = Top + Width/2;
  6. Lastly you’ll call the two values of the Anchor point in an array, from the last two Variables created.
    • [x, y]

Part I: Modify Shape Layer – Size Property

SourceRectAtTime_Shape
  1. Step One: Add a Slider Controller to the shape layer. This will adjust the padding around the type.
  2. Step Two: Open the shape layer under the property Rectangle 1 > Rectangle Path 1 > Size property. This expression code will link the relationship to the text layer.
    • Create variable s again and then = sign and then use the pick-whip to link this to the Text layer. After that add the code .sourceRectAtTime();
    • Example: s=thisComp.layer("Text").sourceRectAtTime();
  3. Step Three: Copy and paste the code for Variables of Height and Width from the first expression.
  4. Step Four: Create a Variable that will hold the Slider. We will name this Padding. Type = and use the pick whip to link to the slider.
  5. Step Five: Write out theX and Y Variables to equal the sum of its value Width or Hight plus the padding.
  6. Step Six: Call the dimensions of the Size property [x, y]

Part II: Modify The Shape Layer – Anchor Points

Currently the animation of type and shape layer will default to push out from the center. Because of x = Left + Width/2; and y = Top + Width/2; So to counteract that code must me modified in the anchor point property of the shape layer.

  1. Step One: Click on the Transform Property Group of the Shape Layer and click on the stop watch next to Anchor Point.
  2. Step Two: Copy and paste the same expression as written in Part I. Delete the Variable Padding, it is not needed. Add variables for the Top=s.top; and Left=s.left; attributes.
  3. Step Three: Adjust X and Y variables to counteract the center alignment, by added a negative sign in-front of the 2 x = Width/-2 - Left ; and y = Width/- 2 - Top;
  • Note 1: If you want the text to animated from the right bottom corner instead of the left. Change the value on X = Width/2 - Left;
  • Note 2: Make sure you parent the Text Layer to the Shape Layer
  • Note 3: When animating the scale property on the text layer. Set the Scale to Zero and then add key frames for the Range Selector.

How to Add an Expression Slider Controller:

On the top screen click on Effects > Expression Controls > Slider Control

AE Expression Controls

It works based on the attributes added to the code. These four include [top, left, width, height].