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

How to find the bounding box of a shape?

Community Beginner ,
Jan 30, 2025 Jan 30, 2025

Copy link to clipboard

Copied

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:

sergey_1079_0-1738295155351.png

 

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.
TOPICS
How to , Scripting

Views

238

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 ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

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.

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 Beginner ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

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

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 Beginner ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

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

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 ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

That makes more sense, but a little beyond me.  Have you seen this excellent resource:

https://ae-scripting.docsforadobe.dev/other/shape/

If I am reading that correctly, you can point to a shape.  Whether you can get to a bounding box after that I'm not sure.  

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
Participant ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

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

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 Beginner ,
Jan 31, 2025 Jan 31, 2025

Copy link to clipboard

Copied

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

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
Participant ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

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.

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 Beginner ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

Convave shapes do not always touch their bounding box with their vertices, they touch them with Bezier curves between vetrices, which requires a fair amount of math to figure out, I'm trying to avoid doing that.

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
Participant ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

Ok got your point

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 Beginner ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

In fact, your logic doesn't always work for convex shapes either:

sergey_1079_0-1738419499804.png

 

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
Participant ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

Do you need a scrit to read the value just once. Or an expression to continuously update?

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
Participant ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

When you create null on path (Trace) this is the expression applied to the null position.

var pathLayer = thisComp.layer("Shape Layer 1"); 
var progress = thisLayer.effect("Pseudo/ADBE Trace Path")("Pseudo/ADBE Trace Path-0001")/100; 
var pathToTrace = pathLayer("ADBE Root Vectors Group")(1)("ADBE Vectors Group")(1)("ADBE Vector Shape"); 
pathLayer.toComp(pathToTrace.pointOnPath(progress));

In the same way, you may sample a number of values to collect positions on the path, then get the Min and Max out of the collected data.

Here is the expression and a screenshot of the setup

var minOrMax = effect("Minimum")("Checkbox");
var pathLayer = thisComp.layer("Shape Layer 1"); 
var pathToTrace = pathLayer("ADBE Root Vectors Group")(1)("ADBE Vectors Group")(1)("ADBE Vector Shape");
var steps = effect("Samples number (integer)")("Slider"); // to get a whole number
var stepSize = (1/steps);
var xCollection = [];
var yCollection = [];
for (var i = 0; i < steps; i++){
	var sampledPoint = pathLayer.toComp(pathToTrace.pointOnPath(stepSize * i));
	xCollection.push(sampledPoint[0]);
	yCollection.push(sampledPoint[1]);
}
var minX = Math.min.apply(null, xCollection);
var maxX = Math.max.apply(null, xCollection);
var minY = Math.min.apply(null, yCollection);
var maxY = Math.max.apply(null, yCollection);
var minimum = [minX,minY];
var maximum = [maxX,maxY];
if (minOrMax == true) {var selection = minimum} else {var selection = maximum;}
selection;


Screenshot 2025-02-01 233205.png

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
Participant ,
Feb 01, 2025 Feb 01, 2025

Copy link to clipboard

Copied

LATEST

Sorry I forgot to remove the integer text from the comment and slider name, it's not required at all

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