Keeps the anchor point automatically centered based on the current size of a text layer.
// Get the size of the text layer's bounding box
s = sourceRectAtTime(time, false);
// Calculate the center of that box
anchor = [s.left + s.width / 2, s.top + s.height / 2];
// Return the centered anchor point
anchor
Apply this to the Anchor Point property of any text layer.
It works best when the text is not parented to anything or when you're using expressions to position things relative to the anchor point.
Alright, so here’s what’s happening:
sourceRectAtTime(time, false)
gives us the bounding box of the text—its width, height, and how far it’s offset from the layer’s top-left.
s.left
and s.top
tell us where the box starts relative to the layer’s anchor.
By adding half the width and height, we get the center of the box.
The result is a point that keeps your anchor locked to the center of the text—even if the text changes or animates.
This is especially useful when you're:
Animating scale or rotation and want it to stay centered
Swapping text dynamically (like with templates or Essential Graphics)
Avoiding that annoying offset when your anchor is stuck in the top-left corner
Just copy the full expression code from the top of this page. Then Alt-click (or Option-click on Mac) the stopwatch on the property you want to animate. Paste the code into the editor and that's it. If you’re not sure which property to use, check the "Where to Apply" section above.
First, make sure your project is using the JavaScript engine (go to File > Project Settings > Expressions). Also double-check for missing characters, and see if the code requires parenting a layer. If so, there will be a comment in the code explaining what needs to be connected.
Take a look at the "How It Works" section on this page. It explains each part of the expression in plain language so you can understand how everything works together.
Yes, absolutely. Most expressions include easy-to-edit variables near the top and comments that guide you on what to change. You can also link sliders or checkboxes using Expression Controls if you want more control in the timeline.
Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.
In most cases, yes. These expressions are designed to adapt to your comp’s resolution and frame rate. If anything specific needs adjusting, it’ll be noted in the code or in the "How It Works" section.
Explore more expressions in this category