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

sourceRectAtTime for mutliple text layers

Community Beginner ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi So I have 3 text layers - each layer the text is a different font size.


I want to be able to say her - make the box as big as the longest text layer.

so far I have this

L=thisComp.layer("Name");

X=L.sourceRectAtTime().width;

Y=L.sourceRectAtTime().height;

P=thisComp.layer("Control").effect("Slider Control")("Slider");

[X,Y]+[P,P]

which is working great to fit the box to the top line of text but sometimes the second line of text, another later "job title" may be longer than the "name"

can I edit my "L" for this?

thank you!

Views

2.6K

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
community guidelines
Mentor ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi!

You have to circle through your layers to find the longest one.

layersincomp = thisComp.numLayers;

maxWidth = 0;

for (n = 1; n <= layersincomp; n++){

     L=thisComp.layer(n);

     X=L.sourceRectAtTime().width;

    

     if (maxWidth < X){

          maxWidth = X;

     }

P=thisComp.layer("Control").effect("Slider Control")("Slider");

boxWidth = maxWidth+P;

[boxWidth, value[1]];     // set up heigth manually, it's not changing, is it?

Didn't test the code, but should go in the right direction.

*Martin

Votes

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
community guidelines
Community Beginner ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Thank you so much for your reply!

No the height isn't changing

This looks great, definitely in the right directions, but it isn't working yet, 

Is this in addition to my code or instead of? And are there parameters here I have to define?

Sorry I'm a bit of a noob but trying to get my head around how it works so I can solve these issues for myself in the future.

Thanks

Lucy

Votes

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
community guidelines
Mentor ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi Lucy,

I checked the code and corrected it, a brace was missing:

layersincomp = thisComp.numLayers;

maxWidth = 0;

for (n = 1; n <= layersincomp; n++){

     L=thisComp.layer(n);

     X=L.sourceRectAtTime().width;

    

     if (maxWidth < X){

          maxWidth = X;

     }

}

P=thisComp.layer("Control").effect("Slider Control")("Slider");

boxWidth = maxWidth+P;

[boxWidth, value[1]];

This code is instead of your one - but I don't know your overall composition or project.

I created 3 text layers and a shape layer as box, then put the code into the shape-layer -> Content -> Rectangle 1 -> Size. Somehow it's still possible to drag the x-size in the property and make the box larger then it should be - I don't understand why, but you'll never run into this, if the box-size is simple way smaller then the text in the first place. (setting this size seems to be more setting a min-size).

You'll also need to take care of anchor points and position in order to make this work. By default, shape layers always scales from the middle.

*Martin

Votes

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
community guidelines
Community Beginner ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Amazing, its working!! but for some reason no longer actually sizing properly to the text 😕 ( it is resizing when i add text to any of the layers) but only starts expanding once i've added loads of text and as you can see is not fitting desirably.

Screenshot 2018-11-02 at 16.10.03.png

I turned off my position expression and padding control to see if it was these but doesn't seem to make any difference.

Thanks for all your help!

Lucy

Votes

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
community guidelines
Mentor ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi Lucy,

I checked the expression on my side and it's working on loooonng texts, too.

However, I'm still on CC2018 and can only confirm, that's working for this version. But if I see right, the box seems to be cut away on the right side. Is there a mask?

Have a look at the bounding-box: the width seems correct. And I can see, that the box is more then 2000px long, assuming you are working on a 1080p project, the box-size seems to be plausible with this long text.

Let me know.

*Martin

Votes

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
community guidelines
Community Beginner ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi martin

Yes, there is no mask but it is doing funky things.  If I set it up to be the right size and position for long text, it is wrong for short text (hanging around in the middle of the frame) and if I set it up properly for short text it doesn't resize properly for long text (as above) The box is not resizing relatively. 

Very frustrating as otherwise the expression is working and just what I was looking for

Thanks

Lucy

Votes

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
community guidelines
Mentor ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi Lucy!

I've made the little project - maybe you can adapt it for you - at least you can play around with the values and understand how it works.

Dropbox - BoxyBox.aep

It's necessary to set the box-width to 0 manually once. I'm not sure why, but even though there is an expression, I still can drag and change the size-value and (and that's I don't know why) it has effect on the box when I get over the calculated size. I can make the box bigger, then it should be, but not smaller. Maybe this is the issue you got.

Also, setting up position and anchorpoint is a bit tricky, since with shape layers there are at least two of each of them (one for the layer, one for every content). Therefore, it's easy for things to get off...

I hope this helps!

*Martin

Votes

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
community guidelines
Mentor ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

I forgot: I'm an german AE, so you will run into translation issues with the expressions at Box-Anchorpoint.

x = -content("Rechteck 1").content("Rechteckpfad: 1").size[0]/2;

equals:

x = -content("Rectangle 1").content("Rectangle Path: 1").size[0]/2;

and the same for y.

Votes

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
community guidelines
New Here ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

LATEST

@Martin_Ritter 

Do you happen to have the aep file still with you.

I have a similar requirement and I think looking at the aep file might work for me.

Votes

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
community guidelines
Community Beginner ,
Nov 05, 2018 Nov 05, 2018

Copy link to clipboard

Copied

Martin!

Thank you so much, you are a legend. 

And i really appreciate you sending me the files, so good to look through each bit to see what I need.

Much appreciated.

Got there in the end

Lucy

Votes

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
community guidelines
Mentor ,
Nov 05, 2018 Nov 05, 2018

Copy link to clipboard

Copied

Votes

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
community guidelines