-
Dynamically centring 2 text boxes that are right aligned
If anyone can help with the below I’d be very grateful 🙂
I have two text layers in after effects that I want to be responsive to one another but always sit perfectly in the centre of the composition as a right aligned block, dynamically recentring depending on the width of either text box’s text. I have managed to do this with two left aligned text boxes by adding the following expressions to the anchor point of each one respectively but when I switch to right aligned text boxes in the paragraph settings it no longer properly centres the x position and I can see the anchor points off to the right. I’ve tried for hours to get it working with no luck:
The top text box anchor point expression:
s = thisLayer.sourceRectAtTime(thisLayer.sourceTime(1));
r = thisComp.layer(“Size 4 Para 2”).sourceRectAtTime(thisLayer.sourceTime(1))
h = s.height + r.height + 50;
w = Math.max(s.width, r.width);
t = s.top;
l = s.left;TopLeft = [l,t];
TopRight = [l+w,t];
TopCentre = [l+w/2,t];
Left = [l,t+h/2];Centre = [l+w/2,t+h/2];
Right = [l+w,t+h/2];
BottomLeft = [l,t+h];
BottomCentre = [l+w/2,t+h];
BottomRight = [l+w,t+h];
Centre
The second text box (that sits underneath the one above) anchor point expression:
s = thisLayer.sourceRectAtTime(thisLayer.sourceTime(1));
r = thisComp.layer(“Size 4”).sourceRectAtTime(thisLayer.sourceTime(1))
h = r.height + s.height;
w = Math.max(s.width, r.width);
t = r.top;
l = r.left;
TopLeft = [l,t];
TopRight = [l+w,t];
TopCentre = [l+w/2,t];
Left = [l,t+h/2];
Centre = [l+w/2,t+h/2];
Right = [l+w,t+h/2];
BottomLeft = [l,t+h];
BottomCentre = [l+w/2,t+h];
BottomRight = [l+w,t+h];
Centre-[0,t+r.height+50]
Can you please help me adjust the expressions to make them work with two right aligned text boxes? Or perhaps a method using a null might be better? Thanks in advance