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!
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
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:
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
Copy link to clipboard
Copied
Thanks I will try that. So this does not adjust the height only the width?
Copy link to clipboard
Copied
I am not good at code/expressions...
Should this be on position or size?
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
Copy link to clipboard
Copied
Ok thanks Mylenium, I'll try that!
Copy link to clipboard
Copied
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...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now