If the shape is meant to follow the text like a little dog, it's probably easier to parent it to the text.
Then use your size expression, and in the position, use an expression that sets the center of the rectangle at the center of the text, like this:
rect = thisComp.layer("Hello people").sourceRectAtTime(time-s.inPoint,true);
[rect.left + 0.5*rect.width, rect.top+0.5*rect.height];
It should work (provided that the anchor point of the shape is at default ([0,0]) and if there groups between the shape layer and the rectangle their position/anchorPoint should also be at their default)
and is completely independant of justification, number of lines, etc
Yes! That worked PERFECTLY! Plus, adding a padding variable to the SIZE expression gives a uniform padding around the entire rectangle!
Thanks much UQg!
Cheers, you made my day!
I prefer to use the shape group transform for this. one expression, simple. no problem.
reset your rectangle path properties and use the shape group transform ONLY:
set your anchor point to where you wish. make sure its there, no snapping for shape group's anchor point yet unfortunately.
use scale + position to set your shape
set this expression for the scale:
t=thisComp.layer("text"); padding=50; x=t.sourceRectAtTime(time-inPoint,true).width+padding; [x,value]
I keep the Y value free so adjust through the scale property itself.
here's the project file:
1 person found this helpful
Alas that will not work with corner roundedness.
Has this been answered anywhere else?
I think I have fixed this before, but project files not to hand.
I also think it didn't translate to Premiere via Animation Template (despite using sliders to be able to build it)
I've just gone down this rabbit hole myself all morning. I've got something that works realy well enough to roll out at the facility I work at, however I just discovered by accident that the width calculated by sourceRectAtTime seems to ignore spaces. I've got decent "padding", but I'm not liking the inconsistency of the end product ( lots of short words in a line vs verbose gesticulations, or Hyphenated-word-combinations, produce drastically varying box widths.
Anyone know an expression tweak to calculate the actual end-to-end width of the text source, one that includes the spaces?
1 person found this helpful
>sourceRectAtTime seems to ignore spaces
It would ignore leading or trailing spaces, is that what you're describing, or is it internal spaces? What expression are you using?
Thank you Dan!
Correct, its only leading and trailing spaces: I was misinterpreting things. I've still been getting some odd "Jumps" in size and position, based on text.
When I get something I'm happy with, I'll share it here.
Thanks all, and thanks Holtz!