Thank you so much Cassius. It worked perfectly! There’s a minor alignment thing happening when I change the text, but personally I don’t care, the most important thing is that your solution works like a charm.
I had previously used this expressions, which didn’t do what yours do.
Under the Rectangle Path:
s=thisComp.layer(“Main Text”);
w=s.sourceRectAtTime().width;
h=s.sourceRectAtTime().height;
[w,h]
Then this expression under the Rectangle Position after aligning the rectangle with the text’s left border:
s=thisComp.layer(“Main Text”);
w=s.sourceRectAtTime().width/2;
h=s.sourceRectAtTime().height/2;
l=s.sourceRectAtTime().left;
t=s.sourceRectAtTime().top;
[w+l,h+t]
You are a genius!