Skip to main content
Inspiring
March 12, 2021
Answered

two different text layers in one auto-scaling textbox?

  • March 12, 2021
  • 2 replies
  • 2512 views

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]

This topic has been closed for replies.
Correct answer jason_or_jay
I am sorry to say I have not.

Give this a try. All credit goes to Mylenium. 

2 replies

Mathias Moehl
Community Expert
Community Expert
March 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
Martin_Ritter
Legend
March 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

DjinWDAuthor
Inspiring
March 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 🙂

Mylenium
Legend
March 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