-
Autoscale multiple lines of text.
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.