Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Text box with 2 separate text layers adapting to each other

  • Text box with 2 separate text layers adapting to each other

  • Sandro Maia

    September 20, 2022 at 6:41 pm

    Hello everyone.

    I would like to know if it’s possible to have 2 separate text layers side by side inside a shape, with the shape adapting in size to both texts and both texts adapting to each other. I know how to make it with a single text layer but i cant warp my head around with 2 text layers.

    Something like in the image and i really need it to be 2 separate text layers

  • Filip Vandueren

    September 21, 2022 at 8:09 am

    I get how the shape can adapt, but how do the two texts adapt to each other? Just position wise ?

  • Filip Vandueren

    September 21, 2022 at 8:31 am

    If all you need is the smaller text to move to the right if the name gets longer, then parent it to the first text, and give the position this expression:


    As for the shape layer:

    add a shape layer, give it a path, give the path this expression:

    margin = 60;
    t2=thisComp.layer("• This text layer adapts");
    l = t1.toComp([s1.left,])[0] - margin;
    r = t2.toComp([s2.left+s2.width,])[0] + margin;
    t = Math.min(t1.toComp([s1.left,])[1], t2.toComp([s2.left+s2.width,])[1]) - margin;
    b = Math.max(t1.toComp([s1.left,])[1], t2.toComp([s2.left+s2.width,])[1]) + margin;
    createPath( [fromComp([l,t]), fromComp([r,t]), fromComp([r,b]), fromComp([l,b])], [],[], true);

    add a Fill and a Round Corners modifier.

  • Sandro Maia

    September 21, 2022 at 9:57 am

    Hi Filip, this worked perfectly. Is there also a way to keep everything centred to the composition when you type on the second text? Typing on the first text everything is aligned to the centre, but when i type on the second text the shape only expands to the right and doesn’t centre.

    Thank you so much for your help! Appreciated.

  • Sandro Maia

    September 21, 2022 at 11:26 am

    After trying around i’ve managed to do it with this simple expression applied to the “x” position of “John” layer.

    Now everything is centred all the time.

    transform.xPosition - (thisComp.layer("• This text layer adapts").sourceRectAtTime().width/2)

  • Filip Vandueren

    September 22, 2022 at 8:23 am

    Sorry, forgot to get back to you.

    Note that if you’ve added a margin between the layers as I did in my example, you’ll also want to add half of that margin

  • Sandro Maia

    September 22, 2022 at 8:26 am

    Yeah you’re right!

    Thanks Filip!

  • John Collucci

    September 24, 2022 at 12:02 am

    Hi Sandro & Filip, I’m in awe of these posts.

    I’ve been using AE for nearly 20 years, and I use pre-saved scripts for certain common tasks, but have no real depth to how to code them myself. I feel that so much untapped capability exists for most of us.

    Do you recommend any resources to actually learn the language & syntax to solve one’s own problems without relying on internet searches (& hoping someone else can help)?

  • Filip Vandueren

    September 24, 2022 at 9:38 am
Viewing 1 - 9 of 9 posts

Log in to reply.

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