Skip to main content
Participant
August 26, 2021
Question

Attaching Text to the Top of a Scaling Bar

  • August 26, 2021
  • 3 replies
  • 187 views

Hi- I am trying to attach text to the top of a bar.  I am using trim paths to adjust the hight of the bar.  I would like for the text poition to adjust with the bar.  So it increases or decreases vertically the text value remains centered at the top of the bar.  

This topic has been closed for replies.

3 replies

Community Expert
August 26, 2021

If you want to stick something to the top of a stroke or even a rectangle that is changing size you have three very simple options. I'll start with the one that is the least amount of work.

 

The first is to use the Nulls Follow Paths.JSX/Nulls Follow Points script to attach a null to every path point, delete the nulls you don't need, then animate the path. All you have to do to attach a layer to the path point is hold down the Shift key and Parent the layer to the null. You can then offset the position of the layer as needed by just selecting it and dragging the position.

 

The second is to use the size of a rectangle and a simple expression to add the rectangle height to the Y value of the other layer (your text). You can almost create the entire expression using a pickwhip. You also need to tie the Transform Rectangle 1/Anchor point to half the size of the rectangle. For example:

The expression for Position:

y = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size[1];
[value[0], value[1] - y]

 

The last option ties the start and end values of Trim Paths to add to the Y value of the slave layer's Position. Mylenium already gave you that expression. The difficulty with that workflow is that you have to know exactly how many pixels the trim path animation covers. You can find that value by temporarily creating a shape layer rectangle that fits the maximum height of your trim paths layer. This is the least accurate and hardest to control. I would just use my first solution. It requires only about 3 mouse clicks after running the script.

Community Expert
August 26, 2021

It depends on the exact animation that you are trying to do. I would duplicate the bar, use the duplicate as an alpha matte and animate the position of the original bar, it will look as if it's scaled but it's only a position animation. This way you can parent the text to the animated bar and it will stick to it without problems.

A very simple project:
https://shared-assets.adobe.com/link/6b14e87a-73f5-411e-5751-c91f5b26fb71

Mylenium
Legend
August 26, 2021

As easy as using a linear() function on the Y position tied to the trim amount. Pseudo code:

 

mTrim=thisComp.layer("Bar").content("Bar").content("Trim Paths").end;

mStart=500;

mEnd=300;

 

X=value[0];

Y=linear(mTrim,0,100,mStart,mEnd);

 

[X,Y]

 

Mylenium