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

two different text layers in one auto-scaling textbox?

Explorer ,
Mar 12, 2021 Mar 12, 2021

Is it possible to have two different texts (Title in color  and font A and subtext in color and font B)
in one auto-scaling box?
How do I add the 't' (Main text layer) in this script?

s=thisComp.layer("Main title");
t=thisComp.layer("Main text");

w=s.sourceRectAtTime().width;
h=s.sourceRectAtTime().height;

[w,h]

TOPICS
Expressions , How to , Scripting
2.4K
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 3 Correct answers

Mentor , Mar 12, 2021 Mar 12, 2021

Just get sourceRectAtTime() for t, and check for larger values.

The larger values are the ones, you take.

 

So:

s=thisComp.layer("Main title");
t=thisComp.layer("Main text");

s_w=s.sourceRectAtTime().width;
s_h=s.sourceRectAtTime().height;

t_w=s.sourceRectAtTime().width;
t_h=s.sourceRectAtTime().height;

 

w = max(s_w, t_w)

h = max(s_h, t_h)

 

[w,h]

 

*Martin

Translate
LEGEND , Mar 12, 2021 Mar 12, 2021

The correct function is Math.max(). It returns the largest possible value of both your layers, which is what you would want to encompass all text.

 

Mylenium

Translate
Community Beginner , Dec 03, 2021 Dec 03, 2021

Give this a try. All credit goes to Mylenium. 

Translate
Mentor ,
Mar 12, 2021 Mar 12, 2021

Just get sourceRectAtTime() for t, and check for larger values.

The larger values are the ones, you take.

 

So:

s=thisComp.layer("Main title");
t=thisComp.layer("Main text");

s_w=s.sourceRectAtTime().width;
s_h=s.sourceRectAtTime().height;

t_w=s.sourceRectAtTime().width;
t_h=s.sourceRectAtTime().height;

 

w = max(s_w, t_w)

h = max(s_h, t_h)

 

[w,h]

 

*Martin

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 ,
Mar 12, 2021 Mar 12, 2021

Sorry, I'm a newbie to scripts.
I assumed I could just copy yours and it would work but I get an error saying that max is not a function.
Not sure what you mean with check for larger values and where to check those.
I hope you have some patience with me 🙂

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 ,
Mar 12, 2021 Mar 12, 2021

The correct function is Math.max(). It returns the largest possible value of both your layers, which is what you would want to encompass all text.

 

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
Explorer ,
Mar 12, 2021 Mar 12, 2021

I think it should look like this then but I now get an error:
Screen Shot 2021-03-12 at 12.50.56.png

 

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 ,
Mar 12, 2021 Mar 12, 2021

My bad...Got it. Forgot the ;

Thanks again

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
Mentor ,
Mar 12, 2021 Mar 12, 2021

Yeah, sorry. Math.max() it has to be - thanks Mylenium!

 

*Martin

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 ,
Mar 12, 2021 Mar 12, 2021

Sorry...back again...
Both textbox are responding to the text being added. So that is good. However I need to the red text (main title) to be on top and the grey (main text) underneath the red. And both within the white box. I imagine I should add a margin to the height of the "Main text". How can I best accomplish this?Screen Shot 2021-03-12 at 13.53.01.pngScreen Shot 2021-03-12 at 13.58.01.png

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 Beginner ,
Dec 02, 2021 Dec 02, 2021

Did you ever figure this out? I'm following the expression as detailed above and still only have one box following one layer of text. I've been chasing this down for a week.

 

Thanks, 

Jason

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 02, 2021 Dec 02, 2021
I am sorry to say I have not.
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 Beginner ,
Dec 03, 2021 Dec 03, 2021

Give this a try. All credit goes to 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
Explorer ,
Dec 03, 2021 Dec 03, 2021
LATEST

Thanks! That kinda did what I wanted 🙂

One lousy character haha

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 ,
Mar 14, 2021 Mar 14, 2021

The easiest and most flexible approach for this is using my extension Pins & Boxes.

Note that Pins & Boxes creates expressions. So the rigs you create with it also work inside templates and mogrts and also on machines, where Pins & Boxes is not installed.

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
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