Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Expression Error – Auto-Scaling text

  • Expression Error – Auto-Scaling text

  • Finn Hitchcock

    April 17, 2020 at 4:56 pm

    Hi All,

    I’ve found this expression which uses the scale property to auto scale the text depending on the amount of characters.

    here: https://medium.com/@loranallensmith/auto-scaling-text-size-in-adobe-after-effects-560b07a6cca2

    However, when I applied this an error appeared in line 11.

    Could anyone help me fix this, or point me in the direction of a similar working expression?

    Thanks in advance!

    😛

    // This lets us get the width of the textbox containing your content.
    layerWidth = thisLayer.sourceRectAtTime(time).width;
    // This lets us get the width of the current composition.
    compWidth = thisComp.width;
    // This lets you specify a maximum width that text boxes should not exceed. In this example it’s 90%, but you can set it to whatever you need or even map it to a control.
    // Pro-tip: If you have other content in the same horizontal space as your text, remember to account for that content when setting your maximumWidth.
    maximumWidth = compWidth * .9;
    // This calculates the current percentage of the maximum width that the text layer occupies.
    percentageOfMaxWidth = layerWidth / maximumWidth * 100;
    // We subtract that percentage from 100 to find out how much space we can spare. If the text box can grow a bit, leeway is positive. If it needs to shrink, leeway will be negative.
    leeway = 100 — percentageOfMaxWidth;
    // Finally, return an array of [width, height] scale. 100 is the baseline and leeway is how much the layer needs to grow or shrink to fit.
    [100 + leeway, 100 + leeway]

  • Dan Ebberts

    April 17, 2020 at 5:17 pm

    This line:

    leeway = 100 — percentageOfMaxWidth;

    has an illegal character in it for the subtract operator. It should be:

    leeway = 100 – percentageOfMaxWidth;

    Dan

  • Finn Hitchcock

    April 17, 2020 at 6:43 pm

    Ahhh thank you!!

    Works perfect 😀

Viewing 1 - 3 of 3 posts

Log in to reply.

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