Skip to main content
Adirai Maji
Inspiring
March 4, 2020
Question

How to calculate the distance between anchor point and rect right edge of a text layer?

  • March 4, 2020
  • 1 reply
  • 1567 views

I want to calculate the distance between the anchor point and animated Text layer's right side edge.

 

I 'm fully aware of this can be done with sourceRectAtTime() expression and I know this expression have only 4 parameters which are Top, Left, Width & Hight.

 

If  the text is not animating and it's anchor Point isn't moved (it's [0,0]) I can simply calculate the distance between anchor point to the text's right side edge by (soruceRectAtTime().width/2) it's too easy because the anchor point is in the middle of the text layer. But If the text layer animating. the anchor point will move depends on the current size of the text layer that's being revealed. So I can't use the previous method to calculate the distance between anchor point to the right edge of layer.

 

Can I get help on this???

 

Note : I used expression in SourceText property to animate text layer with substr method. Because I want to have resizing rectangle size and cursor at the edge of text.

 

This topic has been closed for replies.

1 reply

Community Expert
March 4, 2020

To make a calculation between the text layers anchor point, position and size of the text area as calculated by sourceRectAtTime() you need to include all parameters. You cannot access the baseline shift with an expression so horizontal positioning must be based on a baseline shift of zero. You also will have to estimate the average character height. 

 

I am guessing that you are trying to get a shape layer rectangle to stay lined up with the text no matter where the text layer is in the comp. If that is the case you'll also need to reference the Rectangle>Transform>Anchor point,  Rectangle>Transform>Position as well as the shape layer's Transform>Position and Transform>Anchor point values. You can eliminate looking at the shape layer's Position and Anchor point if you lock them. You also need to compensate for ascenders and descenders (h and y) and multiple lines. 

 

Because of all those considerations, I have not been able to come up with a fully automatic system, but I did create a preset with a few sliders that will work just fine.

 

If you create a new shape layer and put it just below a text layer, then apply this animation preset to the shape layer and then Shift + parent the shape layer to the text layer you'll get a working system. You trim the Pad and the X and Y position and then the shape layer sticks to the text layer no matter what you do to it. I hope this points you in the right direction.

 

https://www.dropbox.com/s/p7hlmh3mheo6ymw/Text%20Box.ffx?dl=0