Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions text length before and after a return

  • text length before and after a return

    Posted by Adam Greenberg on November 16, 2022 at 4:04 pm

    Hi everyone, I have an expression set up where a center aligned text places itself to the left margin.

    The text is center aligned so the 2 lines of text will always be centered to itself.

    But in this case, my left margin is on an angle.

    So my challenge is sometimes the 2nd line may be longer than the first line and vice versa, so due to the angle of the guide layer, I need the expression to know which line is longer, I would just add a variable to move this layer a certain amount of pixels to the right if the condition is met, can someone help me with the syntax.

    the expression works when the 2nd line is longer

    The expression as it is right now is on the y of a null ( separate dimensions )

    x= thisComp.layer(“TITRE”).sourceRectAtTime(time).width;

    v= (1920-(x*.56))/-2+1366;


    is there a way it could be;

    x= sourcerectattime before the return;

    y= sourcerectattime after the return;

    v= (1920-(x*.56))/-2+1366;

    w= (1920-(y*.56))/-2+1366;

    if y > x w; else v+20

    I have included the 2 screen shots to show that it does not work when the first line is longer than the line after the return. I also included a reduced version of the project.

    Thanks for any help.

    I realize I can separate the text into 2 lines which would also solve my problem. I wanted to avoid that because my plan is to add further expressions elsewhere if the text is only 1 line, so I would have a variable that looks at the layer height to determine if its 1 line or 2.

    Adam Greenberg replied 1 year, 3 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    November 16, 2022 at 7:03 pm

    If you do the negative time trick, so just your first line shows up at time = -1 and the just the second line shows up at time = -2 (with a source text expression like this):

    if (time < 0){
    txt = value.split("\r");
    if (txt.length > 1 && time < -1.5){

    Then your expression, modified like this should work:

    x= thisComp.layer("TITRE").sourceRectAtTime(-1).width;
    y= x= thisComp.layer("TITRE").sourceRectAtTime(-2).width;
    v= (1920-(x*.56))/-2+1366;
    w= (1920-(y*.56))/-2+1366;
    y > x ? w : v+20
  • Adam Greenberg

    November 16, 2022 at 10:08 pm

    Hi Dan, this idea is great but it is not keeping the text in the same place when line 2 is longer. is there a missing piece in the source text expression ?

  • Dan Ebberts

    November 16, 2022 at 10:42 pm

    Ah, the second expression has a typo. Try it this way:

    x= thisComp.layer("TITRE").sourceRectAtTime(-1).width;
    y= thisComp.layer("TITRE").sourceRectAtTime(-2).width;
    v= (1920-(x*.56))/-2+1366;
    w= (1920-(y*.56))/-2+1366;
    y > x ? w : v+20
  • Adam Greenberg

    November 17, 2022 at 12:25 am

    Thanks Dan, I should have noticed that, LOL.

    works great, thanks again.

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