Skip to main content
THreeSH98
Known Participant
May 8, 2024
Question

Get data about layer boundaries (text, shape, etc.) in expressions?

  • May 8, 2024
  • 1 reply
  • 1280 views

Hello, I have a question. Is it possible to get layer boundary data in expressions?
I watched a video on YouTube:
https://youtu.be/BIwppXzHErY?list=PL79TBmLa4lTRo4RgRmWkcPkwHA6HNGwZz&t=178
And I did the same, but I would like to use a text layer, for example, and have a method that measures the length between the points "length(pos1,pos2);" worked differently, that is, to obtain data between the length of the position point of one layer and the border (for example, the border of a text block or the border of a shape) of another layer. For example I'm typing text and its bounding box seemed to be "pushing out" the squares in size around the frame/border of the text rather than its position point. I know that you can create a similar effect as in the video using “sampleimage” and blur the edges to achieve a smooth transition, but I was interested in another method.

Expression from the video:
var p1 = thisLayer. transform. position;
var p2 = thisComp.layer("Null 1").transform.position;
var ScaleFrom = thisComp.layer("Adjustment Layer 1").effect("Scale From")("Slider");
var ScaleTo = thisComp.layer("Adjustment Layer 1").effect("Scale To")("Slider");
var Hitin = thisComp.layer("Adjustment Layer 1").effect("hitbox Inside")("Slider");
var HitOut = thisComp.layer("Adjustment Layer 1").effect("hitbox Outside")("Slider");
var d = length(p1, p2);
var r = linear(d, HitOut, Hitin, ScaleFrom, ScaleTo);
[r,r]

Sorry if I didn’t write it clearly, I translated my thoughts from Google translator🙏

This topic has been closed for replies.

1 reply

ShiveringCactus
Community Expert
Community Expert
May 9, 2024

For text layers, I think you're asking about the expression: sourceRectAtTime

Which can give you a layer's width and height.  This link has more information:

https://ae-expressions.docsforadobe.dev/layer-sub.html 

THreeSH98
THreeSH98Author
Known Participant
May 9, 2024

I know about "sourceRectAtTime", but this does not answer the question of how to achieve the length between the boundaries of the layers, and not their position point. To achieve the same effect as in the video, only so that the squares or any other layer change their properties from the layer border, and not from the position.

ShiveringCactus
Community Expert
Community Expert
May 10, 2024

There's a way to get the bounding box:

Layer.sourceRectAtTime(t = time, includeExtents = true)

includeExtents will give you a text layer's full bounding box dimensions, not just the width of the text.

 

The positions of the edges of the box can be calculated from the position of the layer as it's the position - width/2 (left) and position + width/2 for the right (or left + width).  

The same goes for the height.