Skip to main content
Participating Frequently
January 31, 2025
Question

How to find the bounding box of a shape?

I have a layer with multiple shapes in it.
How to find the bounding box of a shape made out of bezier curves, like this one:

 

I can see vertices and tangents info inside value property, but nothing similar to 

sourceRectAtTime for a layer. 
Computing bounding box of a concave shape is rather difficult.

13 replies

Inspiring
January 31, 2025

if you can't find a method to it, then you may write a function do do so
- get the specific shape
- get all it's points positions
- get the min and max of all the x values
- get the min and max of all the y values
- lastly the min x and y is the the top left corner of the bounding box, and the max x and y is the bottom right

Translate
Participating Frequently
February 1, 2025

That will only work for convex shapes, not for concave ones, as you see on the image.

Translate
Inspiring
February 1, 2025

Honestly I didn't try it, but I believe logically it would get the bounding box of the shape even if it's a flat line. Unless ae scripting has limitations to prevent this logic from happening.

I'll give it a try.

Translate
ShiveringCactus
Community Expert
Community Expert
January 31, 2025

Just to check, but are you saying you can't use SourceRectAtTime().width:

thisComp.layer("Shape Layer 1").sourceRectAtTime().width

 

Because I just did a quick check using expressions, and it worked for me.  So I think I might be misunderstanding.

Translate
Participating Frequently
January 31, 2025

That works for a layer bounding box, I'm asking about an individual shape bounding box

Translate
Participating Frequently
January 31, 2025

and I looking for JSX API solution to put the code into an extension, rather that an expression

Translate