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

Auto size shape layer to text

New Here ,
Aug 23, 2023 Aug 23, 2023

Copy link to clipboard

Copied

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

Views

228

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Ok thanks Mylenium, I'll try that!

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

Copy link to clipboard

Copied

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...

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