- May 27, 2016 at 9:14 am
Incredible thanks 🙂
Could be better if the second expression, instead of changing the shape’s scale, controlled the rectangle path size, that way any round corners wouldn’t be distorted. I’ll try and figure it out myself but the last line of that expression is a bit much for me this morning 😀
- May 27, 2016 at 9:25 am
… OK i figured it out myself; this in Rectangle 1>Rectangle Path 1>Size will make the box resizing happen before the round corners and other effects. 🙂
t = thisComp.layer(“tessssstr”);
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
margin = 10;
[(tLR-tUL + 2*margin),(tLR-tUL+ 2*margin)]
Thanks again Dan for another great solution 🙂
- December 10, 2016 at 11:36 am
Can you help me in a simple thing?
If i wont to adjust the text, not in the center, but aligned to the left?
I already download your example… but if i change the alignment of my_Text… the box don’t move…
- November 6, 2017 at 1:35 pm
Damn, no reply ☺
want also LEFT aligned box!
- April 16, 2018 at 1:54 am
Thank you very much, I was facing a similar problem and this solved it.
Just a tip for everyone – since I am creating lots of these self adjusting boxes, I decided PARENT the boxes to their respective text layers and then replace:
text_width = thisComp.layer(“my_text”).sourceRectAtTime().width;
text_width = parent.sourceRectAtTime().width;
And so on with the rest of the code. This way you can duplicate both text and box several times and as far as the box is parented to the right text, it will have the right size.
- August 20, 2018 at 5:16 pm
This is not a solution but a workaround. What I did was to simply mask the shape layer to get cropped on the left side (or whichever side you wish). I also repositioned the shape so its center was on top of the beginning of the editable text.
I changed the code a bit as well to match my design:
margin = 0;
text_width = thisComp.layer("my_text").sourceRectAtTime().width*2;
text_height = thisComp.layer("my_text").sourceRectAtTime().height/6;
box_width = text_width + margin*2;
box_height = text_height + margin*2;
Hope this helps.
- July 9, 2019 at 4:11 pm
I’m trying to use this code for a text layer for subtitles, so as the voiceover changes, I have another text keyframe and I’d like the box to adjust as the text changes in width. Seems like the code only is seeing the last keyframe text width size. I’m assuming this is because the code doesn’t execute every time there is a new keyframe…is there a way to do this?
- July 9, 2019 at 7:05 pm
Adam, try adding time value of the keyframe into sourceRectAtTime(), like:
textLayer = thisComp.layer("my_text");
textLayer .sourceRectAtTime(textLayer.key(X).time, false).width;
Where X – your keyframe index inside text layer.
With the same logic, if you only keep it ‘time’ only, instead specifying the exact keyframe, it should update automatically.
- July 18, 2019 at 4:33 am
Is there a way to separate the width so it stays at a static length but the height still changes?
- July 21, 2020 at 8:20 pm
Thanks so much for this. I only have a minor request for you guys:
How can I scale or change the rectangle’s margin proportionally with the text size?
Thanks again for helping.
Log in to reply.