Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Keeping 2 text layers center when the lengths change

  • Keeping 2 text layers center when the lengths change

    Posted by Jay Mueller on September 25, 2015 at 1:14 am

    I am trying to keep the first and last names center on screen as they change. I have first name (1) right justified and last name (2) left justified, placed in the center and attached to a null. My goal is to find an expression that will shift the null’s “x” position to re-center the names when they change. ie: from “jimmy smith” to “ed lichtenstein”. As you can tell the latter of the two names won’t be centered.

    I found the expression below but doesn’t quite do the trick.

    var w1= thisComp.layer(1).sourceRectAtTime().width;
    var w2 = thisComp.layer(2).sourceRectAtTime().width;
    [(thisComp.width-(w1+w2))/2,value[1]]

    Please help and THANK YOU!

    Jay Mueller replied 10 years, 10 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    September 25, 2015 at 2:54 am

    Assuming the null is between the two layers, it would be something like this:

    var w1= thisComp.layer(1).sourceRectAtTime().width;
    var w2 = thisComp.layer(2).sourceRectAtTime().width;
    [thisComp.width/2 -( w2-w1)/2,value[1]]

    Dan

  • Jay Mueller

    September 25, 2015 at 2:40 pm

    Thanks for the quick feedback, but I get similar outcomes as with the previous expression I found. Offset to the left or right, depends on which name is longer. Just curious if you are aware for a fix for this? Thanks again!

    var w1= thisComp.layer(1).sourceRectAtTime().width;
    var w2 = thisComp.layer(2).sourceRectAtTime().width;
    [thisComp.width/2 -( w2-w1)/2,value[1]]

  • Dan Ebberts

    September 25, 2015 at 5:41 pm

    Hmmm…. It works for me. Your text layers aren’t scaled, are they?

    Dan

  • Jay Mueller

    September 25, 2015 at 5:46 pm

    BINGO! That was it. My text layers were scaled to 50%. THANK YOU!!!

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