Copy link to clipboard
Copied
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
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now