ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Center Position of Text Layer for MOGRT

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Martin Gardiner
Center Position of Text Layer for MOGRT
on Jan 30, 2019 at 11:03:36 pm

Have 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?


Return to posts index

Dan Ebberts
Re: Center Position of Text Layer for MOGRT
on Jan 30, 2019 at 11:42:01 pm

I'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



Return to posts index

Martin Gardiner
Re: Center Position of Text Layer for MOGRT
on Feb 4, 2019 at 8:36:14 pm

that worked, thanks!!!


Return to posts index


Tomas Bumbulevičius
Re: Center Position of Text Layer for MOGRT
on Feb 4, 2019 at 9:31:33 pm

Dan'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.


Return to posts index

Martin Gardiner
Re: Center Position of Text Layer for MOGRT
on Feb 15, 2019 at 9:18:50 pm

How 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.


Return to posts index

Dan Ebberts
Re: Center Position of Text Layer for MOGRT
on Feb 15, 2019 at 9:24:33 pm

Try 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



Return to posts index


Martin Gardiner
Re: Center Position of Text Layer for MOGRT
on Feb 15, 2019 at 9:25:52 pm

Perfect, thank you so much!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]