• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Explorer ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

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🙏

TOPICS
Expressions

Views

344

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2024 May 09, 2024

Copy link to clipboard

Copied

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 09, 2024 May 09, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

Thanks for the answer, unfortunately this still does not give me an example of how to calculate the length between one position point and a position point extended to the boundaries of a layer or text block in order to link and convert through linear() this variable length during animation to the properties of other connected layers , as in the example 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]

Maybe it's not possible or I'm just stupid for it. In any case, thanks for your assistance!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2024 May 13, 2024

Copy link to clipboard

Copied

LATEST

Is it that you're trying to get the width of a null layer?  Nulls don't have an actual width, even if they appear to.

 

For any other layer, I think this would work:

var p2 = thisComp.layer("Red Solid").transform.position+thisComp.layer("Red Solid").sourceRectAtTime().width/2;

That would give you "red solid"'s position which is in the center of the solid, plus half the width.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines