Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Align Paragraph Text to middle of box?

  • Paul Levin

    March 28, 2016 at 4:30 am

    Kalle and Enrique,

    Y’all just saved me a HUGE hassle, Kalle for the expression, and Enrique for showing me how to bottom justify.
    For anyone with money to spend, iexpressions has scripts for bottom and center justification.
    I like Kalle’s version better, the price is right. 🙂

  • Evan Dulaney

    August 3, 2018 at 11:09 pm

    I just figured out another solution to this now very old problem. However, my solution only works if the font size remains consistent.

    I set the anchor point of my text layer to 0,0. This puts the anchor point at the bottom of the first line, always.

    Then, adjust the baseline shift in the character panel so that the anchor point aligns with the top of the first line instead of the bottom.

    then, apply an expression to the anchor point property that uses sourceRectAtTime(time,false); to get the size of the layer and adjust the anchor point.

    I only needed mine to be centered vertically, so mine was like this:

    rect = sourceRectAtTime(time,false);
    [transform.anchorPoint[0],rect.height/2];

    but you could also do

    rect = sourceRectAtTime(time,false);
    [rect.width/2,rect.height/2];

  • Matthew Mammola

    March 11, 2019 at 6:01 pm

    wow this is an awesome solution that I wish i understood, but im plenty happy just following your brilliant lead thank you

  • Evan Dulaney

    March 11, 2019 at 6:07 pm

    Well, sourceRectAtTime gets the rectangular pixel dimensions of a layer. you’re putting that info in a variable, and then setting the anchor point to half of that value.

    It’s not the best solution, however, because it can be inconsistent from a typography standpoint. If you’re using lower case letters, and the bottom line doesn’t have any hanger characters (y, g, q, p, j, etc), then the vertical height ends up being different than if there are hanger characters. It’s not an issue if you’re using all caps though ☺

    It’s the best thing I’ve found so far though. Hopefully in the future there will be an option to keep the anchor point always centered vertically.

  • Frederic Antoinette

    November 7, 2019 at 4:47 am

    Hi, I think I figured a way, by using a text box, not sure if it will work if not using a text box.
    Through test I realise that the sourceRectAtTime().top was always fix whatever font, font size or lines there was in my text box.
    Using that info I came out with this code:

    pY = transform.position[1];
    pX = transform.position[0];
    R = thisLayer.sourceRectAtTime(time);
    c = pY + R.top + (R.height/2);
    y = 296 - c + pY;
    [pX,y]

    the 296 value is the Y value i needed my textbox to be vertically centered, since it was a text box and I horizontally aligned and the text itself was horizontally centered I didn’t need to calculate the x value. But I’m sure using the sourceRectAtTime().left and width property, same can be achieve to horizontally center.

    Probably lots of room for improvement, but I hope that this can at least help.

  • Tomas Bumbulevičius

    November 7, 2019 at 12:01 pm

    Hey Frederic, just curious – maybe it would give more easier results by applied two expressions below? The reason for this – any place, where you include random, single-use-case numbers, is a bit tedious to work with in the long run.

    For position:

    W = thisComp.width;
    H = thisComp.height;
    [W/2, H/2]

    For anchor:
    sourceSize = thisLayer.sourceRectAtTime(time, false);
    T = sourceSize.top;
    L = sourceSize.left;
    W = sourceSize.width;
    H = sourceSize.height;
    ([L+ W/2,T+H/2])

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.
    Boxer – Dynamic Text Boxes Template with a Live Preview

  • Marcin Wojtas

    March 29, 2020 at 10:04 pm

    Thomas – this works great. Thank you for this 🙂

Page 3 of 3

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy