ADOBE AFTER EFFECTS: Forum Expressions Tutorials Podcasts Creative Cloud

expression for length of text layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ryan Fyffeexpression for length of text layer
by 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?

See an example video of what I'm talking about:
http://dallasvoice.com/dvtv_track.php?s=345
(look for the nameplates that animate-in at the beginning of each interview)

I've read everything I can get my hands on, but nothing has helped. Any help would be appreciated!
-RY


Return to posts index

Dan EbbertsRe: expression for length of text layer
by 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.


Dan



Return to posts index

cowcowcow
Trent ArmstrongRe: expression for length of text layer
by 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.

(Dan, can you make this more elegant?)

Trent





Trent Armstrong - Creative Cow Leader
http://www.dallasaeug.com


Return to posts index


Dan EbbertsRe: expression for length of text layer
by 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.

Dan



Return to posts index

Ryan FyffeRe: expression for length of text layer
by 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

in short, THANKS THANKS!
RY



Return to posts index

Kiera PolyakovaRe: expression for length of text layer
by 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]



Return to posts index


Juan IbanezRe: expression for length of text layer
by on Jun 5, 2013 at 1:55:03 pm

Kiera where can I take a look at your example? Thanks.


Return to posts index

jay bhanushaliRe: expression for length of text layer
by on Sep 21, 2013 at 8:23:46 am

Hi Keria,

Can we get to see the after effects file you have created?
I would be of great help if you provide us with the after effects project file.

Thanks
Jay


Return to posts index

Fernando HuezoRe: expression for length of text layer
by on Jun 5, 2015 at 8:30:38 pm

How get the Y length too?
the expression is only for X length


Return to posts index


Dan EbbertsRe: expression for length of text layer
by on Jun 5, 2015 at 8:47:00 pm

This is all obsolete. You can now use sourceRectAtTime() to directly get a text layer's width and height.

Dan



Return to posts index

martin jean-sébastienRe: expression for length of text layer
by on Jul 2, 2015 at 10:08:11 am

How this "RectAtTime()" method works? Have you got an example? Can I use it in a script?

Thank you!


Return to posts index

Dan EbbertsRe: expression for length of text layer
by on Jul 2, 2015 at 5:50:46 pm

sourceRectAtTime() works with both expressions and scripts. It returns an object that includes the width and height of the text's bounding box. You would use it like this:

rect = thisComp.layer("text").sourceRectAtTime(time,false);
w = rect.width;
h = rect.height;

Note that these results don't include any scaling applied to the layer, so you may have to account for that separately.

Dan



Return to posts index


martin jean-sébastienRe: expression for length of text layer
by on Jul 2, 2015 at 6:29:29 pm

Wow thank you! Much more easier than before!


Return to posts index

martin jean-sébastienRe: expression for length of text layer
by on Jul 3, 2015 at 8:43:48 am

Can you tell me since which version of after effects we can use this expression?
Thanks!


Return to posts index

Dan EbbertsRe: expression for length of text layer
by on Jul 3, 2015 at 4:01:19 pm
Last Edited By Dan Ebberts on Jul 3, 2015 at 4:25:09 pm

That was implemented in AE CC 2014.2 (I think).

Dan



Return to posts index


Patrick GrossienRe: expression for length of text layer
by on Jan 19, 2016 at 11:58:41 am

this is weird. I'm using CC2015 and sourceRectAtTime doesn't update properly for me.

My text is set up so that it appears over time via an animated slider:

n=thisComp.layer("john.doe@me.com").effect("Tipp Counter")("Slider");
showtext=text.sourceText.substr(0,n);

now I want to attach a blinking cursor to the appearing text at the end.

L = thisComp.layer("john.doe@me.com");
r = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r.left+r.width,r.top+r.height]))

The value is not being updated over time and the value itself is nowhere near it should be.
I also checked what happens with the width of sourceRectAtTime and it doesn't update either when used solo.

Any insight as to what I'm doing wrong? Or is there a bug I'm missing.

Thanks!


Return to posts index

Patrick GrossienRe: expression for length of text layer
by on Jan 19, 2016 at 11:59:27 am

this is weird. I'm using CC2015 and sourceRectAtTime doesn't update properly for me.

My text is set up so that it appears over time via an animated slider:

n=thisComp.layer("john.doe@me.com").effect("Tipp Counter")("Slider");
showtext=text.sourceText.substr(0,n);

now I want to attach a blinking cursor to the appearing text at the end.

L = thisComp.layer("john.doe@me.com");
r = L.sourceRectAtTime(time,false);
fromComp(L.toComp([r.left+r.width,r.top+r.height]))


The value is not being updated over time and the value itself is nowhere near it should be.
I also checked what happens with the width of sourceRectAtTime and it doesn't update either when used solo.

Any insight as to what I'm doing wrong? Or is there a bug I'm missing.

Thanks!


Return to posts index

Rombout VersluijsRe: expression for length of text layer
by on Mar 24, 2016 at 4:28:07 am

I used this code have dynamic textfield which show my comments in a marker. Is there a method how i can set a maxwidth to that textfield so it uses line breaks automatically?


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2016 CreativeCOW.net All Rights Reserved
[TOP]