Lock Gradient Ramp Position to Text

Locks the Gradient Ramp’s start and end points so they stay aligned with your text layer in comp space.

Author:
Videolancer
Source:
https://www.youtube.com/watch?v=raesoUmZu7Y
Category:
Text

Expression Code

thisLayer.toComp(value)

Where to Apply

Apply this to the Start of Ramp and End of Ramp properties of a Gradient Ramp (or 4 Color Gradient, etc.). Works on text layers or any other layer where you want the gradient to stick in place.

How It Works

// Convert the current property’s value (layer space) into comp space
thisLayer.toComp(value)

Step-by-Step Breakdown

  1. The expression looks at the property value of the Gradient Ramp point (Start or End).

  2. Normally, these ramp point values are stored in the layer’s local coordinate system. That means if you move or animate the layer, the gradient points don’t naturally follow.

  3. thisLayer.toComp(value) converts that local value into composition space coordinates.

  4. By doing this, the gradient ramp points stick to the same relative place on the text, even when you move, scale, or rotate the layer.

  5. The result: no more gradients “sliding off” when animating your text—your Start and End of Ramp stay locked to the text itself.

https://www.youtube.com/watch?v=raesoUmZu7Y

Frequently asked questions

How do I use the expression on this page?

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.

The expression isn’t working. What should I check?

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.

I’m not sure what the expression does. Where can I learn more?

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.

Can I customize how the expression behaves?

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.

Can I apply this to other properties too?

Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.

Will it work in comps with different frame rates or sizes?

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.

Related Expressions

Explore more expressions in this category