Activity › Forums › Adobe After Effects Expressions › Center Position of Text Layer for MOGRT
-
Center Position of Text Layer for MOGRT
Posted by Martin Gardiner on January 30, 2019 at 11:03 pmHave been trying a few expressions that I’ve found online, but I can’t get one that works.
I have a text box that dictates the size & position of the white cut out background it’s on with sourceRectAtTime expression, but now I want the text box to always be centred on screen.
What expression can I use, the text layer’s anchor point isn’t centred maybe that’s why it keeps shifting everything way over?
Martin Gardiner replied 7 years, 1 month ago 3 Members · 7 Replies -
7 Replies
-
Dan Ebberts
January 30, 2019 at 11:42 pmI’m guessing you just want to center the x direction, which you could do like this:
r = sourceRectAtTime(time,false);
myCenterX = anchorPoint[0] + r.left + r.width/2;
compCenterX = fromComp([thisComp.width,thisComp.height]/2)[0];
value + [compCenterX – myCenterX,0]If you want to center x and y, it would be like this:
r = sourceRectAtTime(time,false);
myCenterX = anchorPoint[0] + r.left + r.width/2;
myCenterY = anchorPoint[1] + r.top + r.height/2;
compCenter = fromComp([thisComp.width,thisComp.height]/2);
value + compCenter – [myCenterX,myCenterY]Dan
-
Tomas Bumbulevičius
February 4, 2019 at 9:31 pmDan’s method is indeed nice one!
On the other hand, specifically for text boxes most often you will want anchor point to be in a fixed place all the time. Consider adding similar sourceRectAtTime approach, just with a simplified array.
R = thisLayer.sourceRectAtTime(time);
T = R.top;
L = R.left;
W = R.width;
H = R.height;
[L+W/2, T+H/2]Find out more:
After Effects Tutorials: motion design, expressions, scripting. -
Martin Gardiner
February 15, 2019 at 9:18 pmHow do you center it on just the Y axis? I tried changing your X version to Y’s and 1’s instead of 0’s, but that didn’t work.
-
Dan Ebberts
February 15, 2019 at 9:24 pmTry this:
r = sourceRectAtTime(time,false);
myCenterY = anchorPoint[1] + r.top + r.height/2;
compCenterY = fromComp([thisComp.width,thisComp.height]/2)[1];
value + [0,compCenterY – myCenterY]Dan
-
Martin Gardiner
April 2, 2019 at 3:08 pmChanging the template a bit.
What would I write if I want the width of the text box to be full screen 1920px and I just want the height of the box to change with the amount of text.
I can write
var w = s.sourceRectAtTime().width+1000;which would always have enough to cover both sides to the end of the screen. Is that the best approach?
var w = s.sourceRectAtTime().width+1000;
Reply to this Discussion! Login or Sign Up