-
Auto-scale text lines to same width on 1 layer
Hey champs!
I’ve been working on this expression selector thingy that auto-scales every text line to the same width and got it to function decently. However, AE is acting up and refuses to render it consistently.
Below I’ve attached a video (& project file) showing the problem and a weird little hack I found by accident that fixes the glitching sometimes. Any insight on what’s going on here would be interesting to hear.
My theory is that sourceRectAtTime and the expression selector simply aren’t the best friends and need a little kick in the bum to get along again…
I thought perhaps including posterizeTime(0) in the expression selector would be the logical solution, but that doesn’t do anything sadly.
For a quick look, here’s the main code:
maxWidth = effect("Custom Width")("Checkbox") == 1 ? effect("Max Width")("Slider") : sourceRectAtTime(-100).width; // Either based on a pixel value or the first line
i = textIndex-1;
lineWidths = sourceRectAtTime(-100-i).width; // Get all line widths
scaleFactor = (maxWidth/lineWidths)*100; // Calculate a unique scaling factor for each line
(scaleFactor-100)/9; // "Normalize" and divide by scaling % / 100 - 1Some context:
- The code is affecting a scaling animator set to 1000%
- I’m using @filipvandueren ‘s subSourceRect preset to isolate each line in negative time to get their widths for the necessary calculations. Line 1 sits in time -100, line 2 -101, line 3 -102, and so on
Issues:
- Weird glitching, inconsistency
- For some reason, everything past the 4th line doesn’t scale anymore
A potential workaround I tried was to avoid using sourceRectAtTime inside the expression selector and store the line widths in a slider at different times, to then recall them with valueAtTime, but so far I’ve failed and was hoping someone more qualified than me might be able to help or come up with another fix.
Any smart thoughts to tame this little fella would be wonderful🙂
Thanks!