Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

sourceRectAtTime box changing height

Explorer ,
May 19, 2021 May 19, 2021

Hi there,

I have a lower third set up with 3 auto-sizing text boxes. The "Company Name" position is tied to the end of "Person Name".

jakec71401806_0-1621436245634.png

If I use a name that has letters with ascenders and descenders the "Company Name" box gets shifted down and no longer overlaps.

jakec71401806_1-1621436636728.png

Is there a way I can make it so that the "Person Name" box is always the height of a name with both ascenders and descenders even if it has none?

Expression on "size" property

s=thisComp.layer("Left - Person Name");
w=s.sourceRectAtTime().width;
h=s.sourceRectAtTime().height;

[w,h]

Expression on "position" property

var s=thisComp.layer("Left - Person Name");
var w=s.sourceRectAtTime().width/2;
var h=s.sourceRectAtTime().height/2;
var l=s.sourceRectAtTime().left;
var t=s.sourceRectAtTime().top;


[w+l,h+t];

 Thanks in advanced

TOPICS
Expressions , How to
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 20, 2021 May 20, 2021

No worries! They can be confusing at first. 🙂

So here's your current Size expression:

 

 

s= thisComp.layer('Left - Person Name");

w=s.sourceRectAtTime().width;

h=s.sourceRectAtTime().height;

[w,h]

 

 

You're creating two variables here, one for width and one for height, which look at the other layer (Left - Person Name) to set those values. 

If you want the height to be a static value instead, just enter a number for h instead of linking it to that other layer's height. So your code might i

...
Translate
LEGEND ,
May 19, 2021 May 19, 2021

Of course you can always add custom padding values as you see fit. You may just need to branch your code and add a filter that checks for these characters in a conditional. The simpler alternative to that may be to have a separate layer of text that contains both the largest letters (presumably some umlaut like Ö and a minor g) and instead of using the actual text box' height you use that layer's height.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2021 May 19, 2021

If it's workable to do so, it sounds like you can just set the height at a static value, instead of measuring the text layer.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 20, 2021 May 20, 2021

Sorry, I am new to expressions. How do I do that and still have the box width wrap around the text that gets typed in?

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2021 May 20, 2021

No worries! They can be confusing at first. 🙂

So here's your current Size expression:

 

 

s= thisComp.layer('Left - Person Name");

w=s.sourceRectAtTime().width;

h=s.sourceRectAtTime().height;

[w,h]

 

 

You're creating two variables here, one for width and one for height, which look at the other layer (Left - Person Name) to set those values. 

If you want the height to be a static value instead, just enter a number for h instead of linking it to that other layer's height. So your code might instead look like this:

 

s= thisComp.layer('Left - Person Name");

w=s.sourceRectAtTime().width;

h=200;

[w,h]

 

 

You should be able to see what an appropriate value for h is by looking at a "good" example of this title, or you can just trial and error it a bit until you're happy.

 

One other alternative would be linking it to a slider control (Effects > Expression Controls) and set the slider to 200 (or whatever number is appropriate here). That would keep it parked at a constant value, but still give you easy access to the number if you needed to make small adjustments manually. Sliders can also be easily passed through as controls in a Mogrt, if that's what you're building here.


Good luck! Let us know if you need any further help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 20, 2021 May 20, 2021

Thanks for your help that I didn't realise it was that simple!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2023 May 09, 2023
LATEST

The solution was way simpler and I was driving myself crazy. Thank you  Kyle. You're a savior.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 20, 2021 May 20, 2021

Simply replace the "height" related code with a fixed value.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 14, 2022 Dec 14, 2022

I'm not good at coding, but maybe it's useful to someone who stumbles upon this, you have to set the height based on the font style x height. It ignores ascenders an descenders.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2022 Dec 15, 2022

I have coincidentally run into the same problem again! Can you explain what you mean by "font style x height"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines