Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Autoscale multiple lines of text.

  • Autoscale multiple lines of text.

  • Gregory Wannwitz

    October 8, 2021 at 1:02 pm

    I have a composition with 5 lines of text, I would like the text size to reduce if a line exceeds a certain length, defined with a Slider.

    I created a Null and linked all the texts to it.

    On the scale property of Null, I apply an expression that calculates the length of each line of text.

    If a text exceeds the length set with the Slider, the scale property of the Null should automatically shrink.

    I have tested several methods, the closest seems to be with “else / if”, but only the first line of code works.

    So if the too long text line is the 1st, and also the 1st in the code it works, but if another line is even longer, it is ignored, and the null scale does not reduce.

    Attached is the After Effects project, and here is the code I made (I tried with || in the place of &&, and other simplified versions) :

    ——————————————

    text1width = thisComp.layer(“Text 1”).sourceRectAtTime(t=50).width;
    text2width = thisComp.layer(“Text 2”).sourceRectAtTime(t=50).width;
    text3width = thisComp.layer(“Text 3”).sourceRectAtTime(t=50).width;
    text4width = thisComp.layer(“Text 4”).sourceRectAtTime(t=50).width;
    text5width = thisComp.layer(“Text 5”).sourceRectAtTime(t=50).width;
    Max = thisComp.layer(“CONTROLS”).effect(“Text Max Width”)(1);

    if (text1width >= Max && text2width<<Max && text3width<<Max && text4width<<Max && text5width<<Max) {
    NW = Max / text1width * 100;
    } else if (text2width >= Max && text1width<<Max && text3width<<Max && text4width<<Max && text5width<<Max) {
    NW = Max / text2width * 100;
    } else if (text3width >= Max && text1width<<Max && text2width<<Max && text4width<<Max && text5width<<Max) {
    NW = Max / text3width * 100;
    }else if (text4width >= Max && text1width<<Max && text2width<<Max && text3width<<Max && text5width<<Max) {
    NW = Max / text4width * 100;
    }else if (text5width >= Max && text1width<<Max && text2width<<Max && text3width<<Max && text4width<<Max) {
    NW = Max / text5width * 100;
    }else { NW = 100;
    }
    [NW,NW]

    ——————————–

    Thanks in advance for your time and if you can help

    Best regards.

  • Dan Ebberts

    October 8, 2021 at 1:22 pm

    Try this:

    text1width = thisComp.layer("Text 1").sourceRectAtTime(t=50).width;

    text2width = thisComp.layer("Text 2").sourceRectAtTime(t=50).width;

    text3width = thisComp.layer("Text 3").sourceRectAtTime(t=50).width;

    text4width = thisComp.layer("Text 4").sourceRectAtTime(t=50).width;

    text5width = thisComp.layer("Text 5").sourceRectAtTime(t=50).width;

    Max = thisComp.layer("CONTROLS").effect("Text Max Width")(1);

    textWidthMax = Math.max(text1width,text2width,text3width,text4width,text5width);

    NW = (textWidthMax > Max) ? (Max/textWidthMax)*100 : 100;

    [NW,NW]

  • Gregory Wannwitz

    October 8, 2021 at 1:53 pm

    Thank you so much ! I tried hard but was not using the good way of resolving the problem.

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