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

How to align layers with scripting?

Explorer ,
Jan 19, 2016 Jan 19, 2016

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

TOPICS
Scripting
4.5K
Translate
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

correct answers 1 Correct answer

Community Expert , Jan 19, 2016 Jan 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.

Translate
Community Expert ,
Jan 19, 2016 Jan 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
Translate
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
Contributor ,
Jan 19, 2016 Jan 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

Translate
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
Advocate ,
Jan 19, 2016 Jan 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.

Translate
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
Contributor ,
Jan 19, 2016 Jan 19, 2016

Do you mean keyframed over time, or the text box's bounding box being redrawn? Asking out of curiosity. The equations you all came up with to calculate a static allocated text bos's top/left/bottom/right vertices were all I needed for my purposes, but can see what you mean if the text is being animated.

On a similar topic, has anyone here found any documentation for, or figured out how to use, sourcePointToComp()? It was introduced along with boxTextPos and seems like the values it yields would be much easier to manipulate than the anchor point values from boxTextPos

Translate
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
Advocate ,
Jan 19, 2016 Jan 19, 2016

When you create a box text layer, the allocated box is centered at the origin of the layer, hence its upper left corner in layer coordinates is [-layer.text.sourceText.value.boxTextSize[0]/2, -layer.text.sourceText.value.boxTextSize[1]/2]

When you double click the layer, its textbox appears in the comp viewer and you can change the box size/location.

If you do so, then the box need not remain centered at the origin, and the above coordinates of the upper left corner are wrong.

And there is actually no way to know the coordinates of that corner, which is why the AE's team added that info.

My answer in the post you mentionned, as well as in this thread: Re: Scripting access to hidden text box information, was wrong... sorry about that!!!

As for the sourcePointToComp, i bet it was added to kill any discussion on the same topic.

var L = app.project.item(1).layer(1);

// allocated box:

var T = L.text.sourceText.value;

L.sourcePointToComp(T.boxTextPos); // coordinates of the topleft corner in comp system

L.sourcePointToComp(T.boxTextPos + [T.boxTextSize[0], 0]); // coordinates of the topright corner in comp system

etc

// source rect:

var R = L.sourceRectAtTime(L.time, false);

L.sourcePointToComp([R.left, R.top]); // coordinates of the topleft corner in comp system

etc.

Xavier

Translate
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
Contributor ,
Jan 19, 2016 Jan 19, 2016

Ah, thanks for the clarification. For what it's worth, I was tasked with approaching allocated text boxes that had already been created and positioned by another department, after which I had to calculate their sizes and coordinates.

To calculate the top left coordinate, for example, of such a box, I did the following (cadged from parts of your/David's/Agile's thread) and it ha seemed to work (if no keyframing is in the picture):

Assuming anchor point is centered and [0,0] for the allocated text box (and we programmatically reorient it to such if a user has changed it):

var baseLayerTopLeft = baseLayer.property("Position").value[0] - (  baseLayer.property("ADBE Text Properties").property("ADBE Text Document").value.boxTextSize[0] / 2);

Translate
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
Explorer ,
Jan 20, 2016 Jan 20, 2016
LATEST

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.

Translate
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