Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change size of solid based on string length

  • Change size of solid based on string length

    Posted by Chris Chandras on March 22, 2018 at 7:12 am

    Hey! I’m trying to create text with self-adjusting backgrounds based on the width and height of the text layer. The backgrounds would be rounded rectangle shape layers, and the Rectangle path size would need to change with the length of the sentence. Here are some examples I adjusted manually.

    It’s simple but there would be a ton of them and the verbiage would constantly be changing. Any ideas?

    Chris Chandras replied 8 years, 5 months ago 2 Members · 2 Replies
  • 2 Replies
  • Kevin Camp

    March 22, 2018 at 7:42 pm

    here’s what i do…

    make a rectangle or rounded rectangle shape layer (they are actually the same, the rectangle shape layer has an option for rounding, so i’m not sure why there are two).

    parent the shape layer to the text that you want it to fit around

    then add this expression to the rectangle path>size property:
    pad = 10 ; // set pad value
    if ( hasParent == true ) {
    rect = parent.sourceRectAtTime() ;
    w = rect.width + pad * 2 ;
    h = rect.height + pad * 2 ;
    [ w, h ] ;
    } else
    value ;

    and this expression for rectangle path>position property (not the layer>transform>position property):
    if ( hasParent == true ) {
    rect = parent.sourceRectAtTime() ;
    x = rect.width / 2 + rect.left ;
    y = rect.height / 2 + rect.top ;
    [ x, y ] ;
    } else
    value ;

    then set the rectangle>transform group>position to 0, 0 (again this is different than the layer>transform>position property)

    and you should be good to go, just adjust the pad value in the first expression as needed.

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Chris Chandras

    March 23, 2018 at 5:44 am

    Thank you so much! ???? This is perfect, exactly what I was looking for. Thanks for responding so quickly too ????

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