Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Text that resizes when it hits a margin

  • Text that resizes when it hits a margin

    Posted by Lin Carson on February 22, 2025 at 4:34 pm

    Hi,

    I’m trying to create an expression that will auto-scale down paragraph text once it gets long enough to hit a margin layer, so that it never goes past that point but text can continue to be typed.

    In my project:

    I have a shape layer named “Margin”. I have a paragraph text layer named “Text”. I have the following expression applied to the “Text” Scale property:

    widthTemp = sourceRectAtTime().width;

    rectWidth = (widthTemp*transform. scale[0]) /100;

    x = 100

    var p1 = thisLayer position-100+rectWidth;

    var p2 = thisComp. layer (“Margin”) • position;

    var delta = sub (p1, p2) ;

    var distance = length (delta) ;

    Linear (distance, 0, x, [rectWidth/50, rectWidth/50], [value[0], value [1]]) ;

     

    It does halfway work – when I start typing into the text box, it starts to scale down. But once it goes past the “x” value it starts to scale back up. Is there a way to have it that once it hits x it will continue scaling down to a certain point, and then will carry onto a new line?

    Many thanks for any help!

    Roland R. kahlenberg
    replied 4 weeks ago
    2 Members · 2 Replies
  • 2 Replies
  • Roland R. kahlenberg

    February 25, 2025 at 2:16 pm

    You’re committing recursive calculations – sorta like chasing after your own tail.

    sourceRectAtTime() doesn’t calculate transform.scale but since you needed it, you thought it was a good idea to calculate for scale but as you scale down to hit the target, you also scale the source.

    So, it’s like shooting at a moving target that will always be behind you. 😀

    The trick is to use the Transform Effect to do the scaling.

    I did a screengrab of the solution. FWIW, you can drop this into Claude and ask it to use OCR to convert it into text.

  • Roland R. kahlenberg

    February 25, 2025 at 2:56 pm

    Ooops! Sorry but I made an error – the earlier scale calculated for a fit-to-width solution.

    This one leaves TransformFX.scale at 100 if the text length/width doesn’t breach the margin.

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