Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Text box padding in only X value and not Y Question

  • Text box padding in only X value and not Y Question

    Posted by Merlin Nation on September 25, 2018 at 11:07 am

    Hi all, firstly you’ve helped me a lot on here in the past and thank you for that!

    I have an expression that has been working well for automatically setting the size of a background box based on the text size for a MOGRT template.

    The issue is that I need it to only set the X value or width of the box and not the Y value height.

    Here is the expression at the moment:

    title = thisComp.layer(“Text Line 2”).sourceRectAtTime();padding = effect(“Padding”)(“Slider”);[title.width + padding, title.height + padding];

    This is linked to a slider that controls that padding.

    The reason this is an issue is because the text is all caps and when you add a comma to the text the height of the background box increases and that needs to stay consistent as there are multiple lines of text below it in the layout.

    I tried putting in a manual value for the Y height:

    title = thisComp.layer(“Text Line 1”).sourceRectAtTime();padding = effect(“Padding”)(“Slider”);[title.width + padding, title.height + 26];

    But it still increases the box height when you add a comma so I’m obviously doing something wrong.

    I guess the solution is connecting only the X value to the padding slider but I’m unsure how to do this.

    Any help gratefully received as always.

    Thanks very much,
    Merlin

    title = thisComp.layer("Text Line 2").sourceRectAtTime();padding = effect("Padding")("Slider");[title.width + padding, title.height + padding];

    Merlin Nation replied 7 years, 11 months ago 3 Members · 6 Replies
  • 6 Replies
  • Scott Mcgee

    September 25, 2018 at 11:44 am

    The expression isn’t wrong, it’s because the comma descends below the baseline, which adds more height to your text, which in turn makes the expression recalculate it self (sourceRectAtTime())

    Dan Ebberts addressed something for someone else a while back.

    https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=37002&univpostid=37002&pview=t

    Hope this helps.

  • Kalleheikki Kannisto

    September 25, 2018 at 1:46 pm

    The problem is that the value of title.height changes depending on your text. I would suggest rounding the value to the closest multiple of the line spacing to avoid this issue.

    Should be something like this:

    linespacing = XXX; // replace XXX with your line spacing value
    title = thisComp.layer("Text Line 2").sourceRectAtTime();
    padding = effect("Padding")("Slider");
    [title.width + padding, linespacing*Math.round(title.height/linespacing) + padding]

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Merlin Nation

    September 25, 2018 at 2:56 pm

    Thanks for your reply Kalleheikki,

    I didn’t explain myself properly as the other lines of text will be in separate comps so the line spacing is actually set by hand as they are converted into MOGRT templates for Premiere and that has to deal with multiple lines of text as separate inputs.

    If that makes sense!

    Thanks again,
    Merlin

  • Kalleheikki Kannisto

    September 25, 2018 at 3:37 pm

    Well, if it is just one line and the text size doesn’t change (does it?), you can replace the entire second half of the result, meaning the y-dimension or height, with a fixed number.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Merlin Nation

    September 25, 2018 at 3:55 pm

    Thanks very much Kalleheikki, that works a treat.
    Cheers,
    Merlin

  • Merlin Nation

    September 25, 2018 at 3:56 pm

    Thanks Scott, that’s really helpful.

    It’s a bit fiddly but I got it working eventually.

    Thanks again,
    Merlin

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