ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Is there a way to keep a block of text always vertically centred?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Darryl Torke
Is there a way to keep a block of text always vertically centred?
on Jun 18, 2014 at 6:04:41 pm

I am making a template for a basic AE user in which the user inputs some text. The paragraph setting of the block of text is set to 'center', so that handles itself. However, I was wondering if there was the equivalent of a vertical 'center' that would always keep the text block in the middle of the screen regardless of how many lines the text was.

As I have it set the user has to manually move the text block up and down which gives room for error. I'd like it to be set-it-and-forget-it ideally.


Return to posts index

Kevin Camp
Re: Is there a way to keep a block of text always vertically centred?
on Jun 18, 2014 at 9:28:31 pm

that would be nice (you might suggest it with a feature request):

https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform


you can do it if you force the user to type hard returns (so you wouldn't want to use a block). if you do that, you can use an expression like this to count the hard returns and the change the position accordingly:

offset = 24;
txt = text.sourceText.split('\r');
y = (txt.length-1)*offset;
value-[0,y]


you just need to figure out the offset value for the font/size that you are using.

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Darby Edelen
Re: Is there a way to keep a block of text always vertically centred?
on Jun 18, 2014 at 10:43:50 pm

Here's an animation preset that will center text vertically.

7634_centertextvertically.ffx.zip

The preset applies two sliders to the text layer. The first one needs to match the line height of the text and the second defines the maximum number of lines the expression selector will work with (if more lines than that value are entered then it will no longer vertically center, use a high value).

It also applies a text animator and expression selector that work together to offset the anchor point of all lines of text by the same amount based on how many lines of text there are.

This works with paragraph text or point text. There's no way to dynamically resize a paragraph text layer's bounding box so you'll likely need a very tall bounding box if using paragraph text. You may need to adjust the layer's anchor point some to get the positioning you desire.

Darby Edelen


Return to posts index


Darryl Torke
Re: Is there a way to keep a block of text always vertically centred?
on Jun 19, 2014 at 2:04:48 am

Thanks so much guys. Crazy AE doesn't have this feature innately, but what can you do.


Return to posts index

John Mitchell
Re: Is there a way to keep a block of text always vertically centred?
on Dec 2, 2016 at 4:17:36 am

Kevin - that's brilliant!

Your script is better than one that automatically centres the text on layer because that will automatically centre it around any vertical point. The offset needs to be half the value of the line spacing value - I don't know if you can reference that with an expression. I tried to search the web and it seems you can't - but I'm an expression novice.

So I did it with blunt force - first I set my line spacing to 0, then I added the line spacing animator control to the text layer.

I then adjusted the expression to:

temp = thisComp.layer("Text1").text.animator("Animator 1").property.lineSpacing[1]
offset = [temp]/2;
txt = text.sourceText.split('\r');
y = (txt.length-1)*offset;
value-[0,y]

Where it says "Text1" - that is the layer name of the text layer.

If you don't want to rename your text layers then you can always use a Control slider on a separate layer. I created one called LineSpacing and pickwhipped the line spacing animator control to it.

You then have to adjust that expression unless you want to indent as well as line space to:

temp = thisComp.layer("LineSpacing").effect("Slider Control")("Slider");
[0, temp]

Then the expression for the text value position property is:

temp = thisComp.layer("LineSpacing").effect("Slider Control")("Slider")
offset = [temp]/2;
txt = text.sourceText.split('\r');
y = (txt.length-1)*offset;
value-[0,y]

The only thing you lose with this is the AUTO setting in line attributes but I have found in the past that most fonts simply use the font size value for that.

temp = thisComp.layer("LineSpacing").effect("Slider Control")("Slider")
offset = [temp]/2;
txt = text.sourceText.split('\r');
y = (txt.length-1)*offset;
value-[0,y]




Return to posts index

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