ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change size of solid based on string length

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Chris Chandras
Change size of solid based on string length
on Mar 22, 2018 at 7:12:37 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?


Return to posts index

Kevin Camp
Re: Change size of solid based on string length
on Mar 22, 2018 at 7:42:37 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


Return to posts index

Chris Chandras
Re: Change size of solid based on string length
on Mar 23, 2018 at 5:44:37 am

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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]