Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions expression for length of text layer

  • expression for length of text layer

    Posted by Ryan Fyffe on November 6, 2008 at 8:44 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:
    https://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

    David Cabestany replied 8 years, 7 months ago 12 Members · 19 Replies
  • 19 Replies
  • Dan Ebberts

    November 7, 2008 at 12:01 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

  • Trent Armstrong

    November 11, 2008 at 4:10 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
    https://www.dallasaeug.com

  • Dan Ebberts

    November 11, 2008 at 5:39 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

  • Ryan Fyffe

    November 12, 2008 at 4:26 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 😀

    in short, THANKS THANKS!
    RY

  • Kiera Polyakova

    February 23, 2009 at 11:22 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]

  • Juan Ibanez

    June 5, 2013 at 1:55 pm

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

  • Jay Bhanushali

    September 21, 2013 at 8:23 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

  • Fernando Huezo

    June 5, 2015 at 8:30 pm

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

  • Dan Ebberts

    June 5, 2015 at 8:47 pm

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

    Dan

  • Martin Jean-sébastien

    July 2, 2015 at 10:08 am

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

    Thank you!

Page 1 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy