Skip to main content
Participating Frequently
Jan 31, 2025 3:49 AM UTC
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
Jan 31, 2025 11:32 PM UTC

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
Feb 1, 2025 1:29 AM UTC

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

Translate
Inspiring
Feb 1, 2025 12:48 PM UTC

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
Jan 31, 2025 10:10 AM UTC

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
Jan 31, 2025 11:21 AM UTC

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

Translate
Participating Frequently
Jan 31, 2025 11:28 AM UTC

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

Translate