Copy link to clipboard
Copied
I have a text layer in a text box. With fewer words I want the text to be at a maximum font size and as more words (and lines) are added I want the font size to scale down to a minumum size.
I have a null controller with a slider control (output) with this code
var driver = thisComp.layer("Display Text").sourceRectAtTime().height;
var dMin = 845;
var dMax = 1300;
var pMin = 305;
var pMax = 240;
linear(driver, dMin, dMax, pMin, pMax)
On the source text of text layer I have this code.
var FS = thisComp.layer("Controller").effect("Output")("Slider"); text.sourceText.style.setFontSize(FS).setLeading(FS)
When I add words and lines I can see in the properties panel that the font size is going down, but it still displays at the original (max) font size.
Copy link to clipboard
Copied
Weird things can happen when you create an expression loop where 2 or more expressions depend on each other's results. In this case, you're setting font size based on sourceRectAtTime(). But sourceRectAtTime() is affected by font size, so the result can be unpredictable. As I recall, in the early days of expressions, the expression engine was more adamant about not letting you set up dependent loops like that.
Copy link to clipboard
Copied
Thanks Dan.
The curse of the recusive.