Skip to main content
Participating Frequently
December 6, 2021
Question

AE ExtendScript get the x-y dimensions of a custom shape path?

  • December 6, 2021
  • 1 reply
  • 811 views

Hello,

 

So I wanted to create a script where it will detect dimensions of a custom shape path so I can resize it to the dimensions I want (or at least prompt the user to resize it if scripting doesn't allow me to re-size it automagically).

 

Thank you.

This topic has been closed for replies.

1 reply

Mathias Moehl
Community Expert
Community Expert
December 6, 2021

Do you mean the bounding box of the shape? There is no direct way to retrieve that in Ae scripting. To approximate it, you can iterate over all vertices of the shape and calculate the min and max of them in both x and y dimension. However, note that this only gives the correct result if there are actually vertices at the minimum and maximum points of the shape. To get an accurate result also in other situations, you need to do pretty complex bezier shape calculations.

Also note, that the shape vertices are in layer space, so depending on your needs, you also need to convert them to comp space.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Participating Frequently
December 6, 2021

Thank you very much for the answer! I kept it simple and just looked at the layer dimensions and got what I needed. Now I have a 2nd question.

 

What I'm trying to do is add a polystar shape into an existing shape layer. I'm doing this where the existing selected shape layer has its own vector group, and the script will add the polystar shape in same shape layer, but in its own vector group. This works; however it adds my polystar shape like off to the far right. I was expecting the poly star to appear above the existing shape (see screenshot, the T-Rex is the existing shape, and the polystar is off to the top right off the canvas - this is where it's being placed by the script.).

 

I'm not using any custom weird way of adding the polystar. Just a simple property/addProperty("ADBE Vector Group") and an addProperty("ADBE Vector Shape - Star");

 

I've saved my script as a TXT file for your review; my apologies for amateur scripting, I'm re-learning/novice to JavaScript and ExtendScript

 

Mathias Moehl
Community Expert
Community Expert
December 7, 2021

The location of a shape is based on the combined transform properties of the layer and all shape groups that it is nested in (and the position property of the polystar itself). All of those are properties you can also set with scripting.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects