ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Vertically Align Text Layers via Script

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jonathan Wendt
Vertically Align Text Layers via Script
on Dec 7, 2015 at 7:29:39 pm

I've been fiddling with trying to get this to work for a while, but I just can't seem to wrap my head around it. It's easy to horizontally align text layers via scripting because you can just use ParagraphJustification.CENTER_JUSTIFY, but there isn't a similar control to do the same thing for the y-axis. Essentially I'm trying to figure out how to use this button via my script.



I can grab the layers values for top, height, composition height, and was able to correctly use the examples from this old thread to make it align to the top of the comp, or the bottom of the comp, but haven't been able to wrap my head around coming up with the equation to make it align to the middle of the comp. Any help is greatly appreciated!


Return to posts index

Walter Soyka
Re: Vertically Align Text Layers via Script
on Dec 7, 2015 at 8:57:14 pm

Since you're trying to align the middle of the text block to the middle of the the comp instead of the bottom of the text block to the bottom of the comp, you have to divide both heights by two.

I've modified Dan's code accordingly:

var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers[0];
var myRect = myLayer.sourceRectAtTime(0,false);
var myPos = myLayer.property("Position").value;
var myY = myPos[1] + myRect.top + myRect.height/2;
var deltaY = myComp.height/2 - myY;
myLayer.property("Position").setValue(myPos + [0,deltaY]);


Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


Return to posts index

Jonathan Wendt
Re: Vertically Align Text Layers via Script
on Dec 7, 2015 at 9:01:49 pm

Thank you so much! I knew it was something simple along those lines. I swear I thought I tried every permutation of that, but I must've just missed the right one. This was exactly what I needed.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]