Highlighted

sourceRectAtTime box won't fit text

Community Beginner ,
May 12, 2020

Copy link to clipboard

Copied

Hi everyone!

 

I am completely new to expressions and facing this issue. I have not found anyone with the same problem yet, so I'll ask here. The rectangle is a shape layer with a sourceRectAtTime expression in its path - size. The text is a text layer. As you can see the box is too small, when it is supposed to fit around the text, no?

 

gneisenauer_0-1589295581367.png

 

gneisenauer_1-1589297663577.png

 

this is the expression i wrote:

 

var s = thisComp.layer("Text");
var w = s.sourceRectAtTime().width;
var h = s.sourceRectAtTime().height;

[w,h];

 

I also tried this:

 

L=thisComp.layer("Text");
X=L.sourceRectAtTime().width;
Y=L.sourceRectAtTime().height;
P=thisComp.layer("control layer").effect("Einstellungen für Schieberegler")("Schieberegler");
[X,Y]+[P,P]

 

P is a slide controller for size of the rectangle.

 

But it also results in a rectangle that is too small for the text.

Can you help? Like I said this is the first time I am working with expressions so please forgive any noob mistakes.

 

Best Wishes,

gneisenauer

 

Topics

Error or problem, Expressions, Scripting

Views

626

Likes

Translate

Translate

Report

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

sourceRectAtTime box won't fit text

Community Beginner ,
May 12, 2020

Copy link to clipboard

Copied

Hi everyone!

 

I am completely new to expressions and facing this issue. I have not found anyone with the same problem yet, so I'll ask here. The rectangle is a shape layer with a sourceRectAtTime expression in its path - size. The text is a text layer. As you can see the box is too small, when it is supposed to fit around the text, no?

 

gneisenauer_0-1589295581367.png

 

gneisenauer_1-1589297663577.png

 

this is the expression i wrote:

 

var s = thisComp.layer("Text");
var w = s.sourceRectAtTime().width;
var h = s.sourceRectAtTime().height;

[w,h];

 

I also tried this:

 

L=thisComp.layer("Text");
X=L.sourceRectAtTime().width;
Y=L.sourceRectAtTime().height;
P=thisComp.layer("control layer").effect("Einstellungen für Schieberegler")("Schieberegler");
[X,Y]+[P,P]

 

P is a slide controller for size of the rectangle.

 

But it also results in a rectangle that is too small for the text.

Can you help? Like I said this is the first time I am working with expressions so please forgive any noob mistakes.

 

Best Wishes,

gneisenauer

 

Topics

Error or problem, Expressions, Scripting

Views

627

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 12, 2020 0
Adobe Community Professional ,
May 12, 2020

Copy link to clipboard

Copied

What happens when you reset your character panel? What is the scale value of the text layer?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 12, 2020 0
Adobe Community Professional ,
May 13, 2020

Copy link to clipboard

Copied

The sourceRect is measured in layer space, not in comp space. That means, if you scale your layer (or parent it and scale the parent, for example), the sourceRec will stay the same and not grow/shrink accordingly.

So if your layer scale is 150%, for example, you need to multiply the sourceRect size with 1.5.

 

For an easy - no coding at all - solution also see my extension Pins & Boxes

https://aescripts.com/pins-and-boxes/

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 13, 2020 3
Community Beginner ,
May 17, 2020

Copy link to clipboard

Copied

thanks, that was it!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 17, 2020 0
Community Beginner ,
May 14, 2020

Copy link to clipboard

Copied

The sourceRectAtTime method does not reflect the relative scale and gets the absolute size of the text layer.

So to find the relative size.


You need to multiply the text size by the scale as in the expression below.

 

var target = thisComp.layer ("text");
var rect = target.sourceRectAtTime ();
var target_scale = target.transform.scale;
var padding = thisComp.layer ("control layer"). Effect ("Einstellungen für Schieberegler") ("Schieberegler");

var w = ((rect.width + padding) / 100) * target_scale[0];
var h = ((rect.height + padding) / 100) * target_scale[1];

[w, h];

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 14, 2020 2
Community Beginner ,
May 17, 2020

Copy link to clipboard

Copied

perfect, thank you very much for that!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 17, 2020 0