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

Auto size shape layer to text

New Here ,
Aug 23, 2023 Aug 23, 2023

Can't find this anywhere on the web so please help me out!
I want to create a shape layer (box behind a text layer) that adjusts to the text layer depending on what text I am writing.
But I only want the shape layer to adjust on the width not the height.

I already have the expression/code for a shape layer to adjust to a text layers with its width and height but not one for width only.
Somebody out there who knows?
Would be grateful!

TOPICS
Error or problem , Expressions , How to
481
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 ,
Aug 23, 2023 Aug 23, 2023

If you have the code already, you can simply dial in a fixed value for the second paramater instead of the .height(). not sure what else you need to know.

 

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 ,
Aug 23, 2023 Aug 23, 2023

Thanks for your reply Mylenium.
The problem is I don't have the right code. This one adjusts both width and height but I just want it to adjust the width.
I cant just erase some letters inside this code I think.
See picture below:

Andreas243269994s2e_0-1692780564828.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
LEGEND ,
Aug 23, 2023 Aug 23, 2023

You can literally find hundrerds of alternate examples, but here you go:

 

mLay(this Comp.layer("Text");

mRect=mLay.sourceRectAtTime();

mPadX=20; //padding width

mPadY=20; //padding height

 

X=mRect.width+mPadX*2;

Y=mRect.height+mPadY*2; //alternatively fixed value: Y=70;

 

[X,Y]

 

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 ,
Aug 23, 2023 Aug 23, 2023

Thanks I will try that. So this does not adjust the height only the width?

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 ,
Aug 23, 2023 Aug 23, 2023

I am not good at code/expressions... 
Should this be on position or size?

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 ,
Aug 23, 2023 Aug 23, 2023

Size:

 

mLay=thisComp.layer("Text");

mRect=mLay.sourceRectAtTime();

mPadX=20; //padding width

mPadY=20; //padding height

 

X=mRect.width+mPadX*2;

Y=mRect.height+mPadY*2; //alternatively fixed value: Y=70;

 

[X,Y]

 

Position:

 

mLay=thisComp.layer("Text");

mPos=mLay.transform.position;

mRect=mLay.sourceRectAtTime();

mPadX=20; //padding width

mPadY=20; //padding height

cHalfX=thisComp.width*0.5;

cHalfY=thisComp.height*0.5;

 

X=mPos[0]-cHalfX+(mRect.width+mPadX*2)*0.5;

Y=mPos[1]-cHalfY+(mRect.height+mPadY*2)*0.5;

 

[X,Y]

 

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 ,
Aug 23, 2023 Aug 23, 2023

Ok thanks Mylenium, I'll try that!

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 ,
Aug 24, 2023 Aug 24, 2023
LATEST

No sorry, the height of the shape layer still changes when I, as an an example, change a "s" to a "S" in my text layer. Have also tried to change the variables in the size code but its still the same...

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