Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Paragraph Alignment Detection

  • Paragraph Alignment Detection

    Posted by Julian Chojnacki on March 27, 2023 at 5:36 pm

    Hey folks,

    what are your workflows for detecting a text layer’s paragraph alignment, since you can’t directly access it via expressions?

    I found a solution to my case yesterday, which might be a little specific, but I thought I’d share it anyway.

    My setup consists of a text layer where one line is text, and the next line is a pipe character stretched into a box. Changing the paragraph alignment on this would only reposition the text, and not the pipe character, since that one is stretched in the opposite direction with a scaling animator.

    But now, knowing that only one part of the layer moves, we can measure it against the other part, and got something tangible to detect the paragraph alignment with. SourceRectAtTime seemed perfect for this, so the following code on anchor point grouping alignment made the stretched pipe character always follow the first line’s position:

    const a = sourceRectAtTime(-3);

    const b = sourceRectAtTime(-1);

    if (a.left > b.left) {

    rightAligned = [50, 0];

    } else if (a.width < b.width) {

    leftAligned = [-50, 0];

    } else {

    centered = [0, 0];


    One important thing to mention here is that the part we want to compare the changes in alignment to needs to remain static at all times, which means that we need to isolate its bounding box using a scaling animator set to [0, 0] (I did it at time == -3), leaving only the stretched pipe character.

    The negative time 1 in the other sourceRect is just a workaround for some minor bugs that can occur when you leave the parentheses empty.

    Another drawback is that this isn’t optimized for keyframing sourceText yet, which I found to be a little glitchy as well. Apart from that, it’s pretty solid!

    Thrilled to hear your thoughts & ideas!

    Brie Clayton replied 10 months, 4 weeks ago 3 Members · 4 Replies
  • 4 Replies
  • Filip Vandueren

    March 27, 2023 at 9:07 pm

    Hey Julian,

    Interesting question and a cool approach. I hadn’t given it any though.

    I had an idea, to just check the sourcerect width vs left ratio, and at first glance this simple test seems to work for me:

    let sr=thisComp.layer("txt").sourceRectAtTime();
  • Julian Chojnacki

    March 27, 2023 at 11:21 pm

    Filip, your code works brilliantly! Thanks for sharing 🤙

    I tried to generalize my code for all cases and ended up comparing a single characters rect positions in negative time with the positions of positive time source text value… but your technique is so much more straight forward…

    Would you mind explaining your thought process behind it?

  • Filip Vandueren

    March 28, 2023 at 8:07 am

    I quickly did a sourceRect on a text-layer, and watched what the numbers did when I changed alignment, and it made sense: left aligned text starts at around 0,0, center aligned puts the center at 0,0 (so left ends up in the negative range) and right aligned puts the right edge at 0,0 (so the left edge would be at -width)

    Then it clicked that the left/width ratio would give something around 0, -0.5, -1

    Depending on the font design there’s quite some margin of error, so I rounded and clamped. And multiplied by -2 to get 0,1,2 for the three options.

    I’m pretty sure there are outlier cases (maybe with very thin fonts, very short words,…) where this breaks

  • Brie Clayton

    March 28, 2023 at 7:56 pm

    Thank you, Filip!

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