Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Reposition text anchor point depending on characters

  • Reposition text anchor point depending on characters

    Posted by Yan Trudel on July 7, 2017 at 1:57 pm

    I dont know if I can call it a problem because it works, but being someone who still only dabbles a bit in AE expressions I was hoping maybe to optimize or “fool proof” some code.

    I have a text layer that has to be aligned at the bottom, even when there are line breaks. I found this great post on the Adobe forums that solved that problem ( https://forums.adobe.com/thread/1065178 ). (Thanks Dan!).

    But since I needed my text to not move at all, I added an expression to shift the Anchor point according to the presence of certain characters on text line 1 if there is only 1 line, and on line 2 if there are 2 lines of text. Since the text is all caps, only these characters seem problematic : Q $ Ç ; ,

    Everything seems to work fine, but was wondering if there was a chance any of this could backfire in certain situations?

    Position :
    myComp = comp("Comp - Titre")  
    myLayer = thisLayer;
    myRect = myLayer.sourceRectAtTime(0,false);
    myPos = transform.position;
    s = transform.scale;
    myY = myPos[1] + ((myRect.top + myRect.height)*s[1]/100);
    deltaY = myComp.height - myY;
    (myPos + [0,deltaY]);

    Anchor Point :
    Px=transform.anchorPoint[0];
    Py=transform.anchorPoint[1];

    txt = comp("Control_HUB").layer("TITRE").text.sourceText;
    Lignes = txt.split(/\n|\r/).length;
    LDeux = txt.split("\r");

    C = 1;
    Q = 1;
    Pv = 1;
    V = 1;
    D = 1;

    if (Lignes > 1)
    {
    LDeux = txt.split("\r")[1];
    C = LDeux.split("ç").length;
    Q = LDeux.split("q").length;
    V = LDeux.split(",").length;
    Pv = LDeux.split(";").length;
    D = LDeux.split("$").length;

     if(C>1 || Q>1 || V>1 || Pv>1)
    {
    Py=Py-21;
    }

     else if(D>1)
    {
    Py=Py-15;
    }

      else
        Py=Py;
    }

    else if (Lignes == 1)
    {
    LDeux = txt.split("\r")[0];
    C = LDeux.split("ç").length;
    Q = LDeux.split("q").length;
    V = LDeux.split(",").length;
    Pv = LDeux.split(";").length;
    D = LDeux.split("$").length;

     if(C>1 || Q>1 || V>1 || Pv>1)
    {
    Py=Py-21;
    }

     else if(D>1)
    {
    Py=Py-15;
    }

      else
        Py=Py;
    }

    [Px,Py];

    Yan Trudel replied 9 years ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

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