Skip to main content
Participating Frequently
January 19, 2016
Answered

How to align layers with scripting?

  • January 19, 2016
  • 2 replies
  • 4608 views

Hey folks,

maybe a little bit easy question but I didn´t found something on the web until now.

I want to align some layers like with the "alignment" Panel in after effects interface. The goal is to vertical center some shapes.

Is it possible to do this without writing the math by myself?

Cheers

This topic has been closed for replies.
Correct answer Mathias Moehl

No. You need to use the sourceRectAtTime() method of the layers (available for any AVLayer) to figure out the size and placement of the layers and then do the math yourself.

2 replies

Participating Frequently
January 20, 2016

Hey guys, thank you for the answers.

What a pity that this interface feature isnt accessible to scripting.

In my case I found a solution, because all my shapes have an centered anchorpoint, so it is easy to set only the y-position.

Mathias Moehl
Community Expert
Mathias MoehlCommunity ExpertCorrect answer
Community Expert
January 19, 2016

No. You need to use the sourceRectAtTime() method of the layers (available for any AVLayer) to figure out the size and placement of the layers and then do the math yourself.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
tardigrade01
Inspiring
January 19, 2016

I was actually just dealing with this for allocated text, where you cannot use sourceRectAtTime but instead boxTextSize. The math was a little tedious but I solved it by calculating their x,y coordinates for each vertex of the text box and then aligning based on the min or max value of the compared layers.

With a major hat tip to David Torno, AgileUI, and UQg and this thread, where they describe how to calculate the top left, bottom left, top right, and bottom right coordinates of your text box:

ADBE Text Document boxTextSize attribute

UQg
Legend
January 19, 2016

As was pointed out in that linked thread, boxTextSize is not enough to locate the text box (if the user has modified the text box since its creation).

The boxTextPos attribute was added later (in CC20xx, can't remember which one) and, unless the text box hasnt been modified since creation, you'll need that info too.

Xavier.