expression for length of text layer
by Ryan Fyffe
on
Nov 6, 2008 at 8:44:57 pm
Hello everyone,
Is there a way to measure the total width (and height) of a text layer, to automatically update the length (and height) of a shape layer? I produce web news segments with 7-15 lower thirds displays for each video. I'm looking for a more efficient way to re-size each nameplate. Currently I manually re-size each shape layer to fit the name. Is there an expression that will update the shape layer, based on the length (in pixels) of the text layer?
Re: expression for length of text layer by Dan Ebberts on Nov 7, 2008 at 12:01:00 am
You can't do it in a straight-forward way with expressions. There is, however, a hack where you can use sampleImage() to find the extents of a text layer.
The extents are available to scripting, so you could run a script that would go through your project and clean things up for you after you establish all the text. That's probably the way I'd go. Not trivial, but not too tough.
Re: expression for length of text layer by Trent Armstrong on Nov 11, 2008 at 4:10:27 am
temp = thisComp.layer("TEXT").text.sourceText;
s = temp.length;
x = 100 * (s * .175);
[x, value[1]]
I have goofy HACK that might need some tweaking.
Either call your text layer "TEXT" or change the name in the expression. And apply the expression to the Scale of your solid.
I tested it a few times and it seemed to work okay. You'll probably have to adjust the number you multiply "s" by to go with your particular font and tracking.
Re: expression for length of text layer by Dan Ebberts on Nov 11, 2008 at 5:39:35 am
This would work for a mono-spaced font, but I think it would break down with a long string in a proportional font. There's a brute force way of doing this - you create a table of the width of each character (a dedicated font editing program helps). Then your expression just adds up the width of each character in the string. It's a bit of work to set up, but it's fairly accurate.
Re: expression for length of text layer by Ryan Fyffe on Nov 12, 2008 at 4:26:12 am
Wow, Trent. You've completely saved my day! This issue arose because my coworkers remain blissfully ignorant of After Effects and it's wonders. Since they wouldn't learn something new, they're now getting an easy-to-use template for making their own nameplates!
I plugged the script in to the scale property, as you said....and KABOOM! it worked! Just a little bit of tweaking was needed, but it was easy enough to get the X value right :-D
Re: expression for length of text layer by Kiera Polyakova on Feb 23, 2009 at 11:22:05 am
I've used that simple method of changing a box lenth. And I've just added a Slider Control (in text layer, named "BOX X CORRECTION") that corrects the length to exact value (Notice that instead of shape layer I've used simple layer with mask and I just change its X position and I use a link to text layer with an offset of two layers above (-2))
temp=thisComp.layer(thisLayer,-2).text.sourceText;
xps = temp.length;
xps = 100 * (xps * .125)-250+ thisComp.layer(thisLayer,-2).effect("BOX X CORRECTION")("Slider");;
if (xps<-140) (xps=-140);
yps=thisProperty[1];
[xps,yps]