Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Auto-scale text depending upon text length

  • Auto-scale text depending upon text length

    Posted by Chris Brady on October 1, 2019 at 11:16 am

    Hi all,

    Is there a way to auto-scale the text so it fits within a defined area of the composition, no matter the length of text.

    Example: The text ‘John Smith’ sits in the centre of the screen with a padding of 500 pixels either side. When the user changes the name to ‘Christopher Smith’ the text layer auto-scales down so 500 pixels padding remains either side of the text.

    Hope that makes sense. Thanks in advance!

    Andrei Popa replied 6 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • Andrei Popa

    October 1, 2019 at 2:33 pm

    Add this to scale:

    var padding = 500;

    value * (width-padding*2)/sourceRectAtTime(time,false).width;

    To make sure the text stays in the middle, you could add this to the anchorPoint and then press ctrl+home to place it in the middle of the comp.

    var myWidth = sourceRectAtTime(time,false).width;
    var left = sourceRectAtTime(time,false).left;
    var myHeight = sourceRectAtTime(time,false).height;
    var top = sourceRectAtTime(time,false).top;
    [left+myWidth/2,myHeight/2+top]

    Andrei
    My Envato portfolio.

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