ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Text box padding in only X value and not Y Question

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Merlin Nation
Text box padding in only X value and not Y Question
on Sep 25, 2018 at 11:07:36 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];


Return to posts index

Scott McGee
Re: Text box padding in only X value and not Y Question
on Sep 25, 2018 at 11:44:56 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=3700...

Hope this helps.


Return to posts index

Merlin Nation
Re: Text box padding in only X value and not Y Question
on Sep 25, 2018 at 3:56:36 pm

Thanks Scott, that's really helpful.

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

Thanks again,
Merlin


Return to posts index


Kalleheikki Kannisto
Re: Text box padding in only X value and not Y Question
on Sep 25, 2018 at 1:46:25 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


Return to posts index

Merlin Nation
Re: Text box padding in only X value and not Y Question
on Sep 25, 2018 at 2:56:28 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


Return to posts index

Kalleheikki Kannisto
Re: Text box padding in only X value and not Y Question
on Sep 25, 2018 at 3:37:34 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


Return to posts index


Merlin Nation
Re: Text box padding in only X value and not Y Question
on Sep 25, 2018 at 3:55:24 pm

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


Return to posts index

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