Activity › Forums › Adobe After Effects Expressions › Attach anchorpoint to the center of the layer
-
Attach anchorpoint to the center of the layer
Posted by Rainier Raydán on August 16, 2017 at 3:02 pmHi! I have this shapeLayer who grows when a text is fill. The position of this layer is already attach to the center of the composition with
thicComp.width/2
now, I need the anchorpoint to be in the center of the width of the layer but I cant figurate out how to do it…this is a image of what Im trying to do

this is the image with the wrong anchorpoint when I fill both text
thanks guys!
Andrei Popa replied 7 years, 9 months ago 3 Members · 7 Replies -
7 Replies
-
Andrei Popa
August 16, 2017 at 3:14 pmThe solution for making the anchor point always in the middle is
tempx = thisLayer.sourceRectAtTime(time,false).width/2 + thisLayer.sourceRectAtTime(time,false).left;
tempy = thisLayer.sourceRectAtTime(time,false).height/2 + thisLayer.sourceRectAtTime(time,false).top;
[tempx,tempy]
but you may run into some problems with the position by changing it with expressions. You may have to also alter the position expression.Andrei
-
Rainier Raydán
August 24, 2017 at 1:58 pmSorry, do you have any idea on how to set the anchor point to upper right or left, center right or left and so?
-
Andrei Popa
August 24, 2017 at 3:30 pm
Here is a “crash course” for the sourceRectAtTime(time, false) function. In the picture you see the values it has for top, left, height and width. What you must remember is that while the anchor point is below the top of the layer the “top” value is negative. Also, if the anchor point is to the right of the left extremity, the left value is negative. You always have negative values for this variables while inside the rectangle. The x position is where the anchor is at its [0,0](where the anchor point is before you do any transformation to it). So for you to move it around, you only have to do some basic geometry. Here is a pic and also the values of x,y for all the positions you needed them. You can combine them as you like for different results.//x values
//left
x = thisLayer.sourceRectAtTime(time,false).left;
//right
x = thisLayer.sourceRectAtTime(time,false).width + thisLayer.sourceRectAtTime(time,false).left;
//mid
x = thisLayer.sourceRectAtTime(time,false).width/2 + thisLayer.sourceRectAtTime(time,false).left;//y values
//top
y = thisLayer.sourceRectAtTime(time,false).top;
//mid
y = thisLayer.sourceRectAtTime(time,false).height/2 + thisLayer.sourceRectAtTime(time,false).top;
//bottom
y = thisLayer.sourceRectAtTime(time,false).height + thisLayer.sourceRectAtTime(time,false).top;
Andrei
-
Atul Rajput
August 9, 2018 at 6:49 amHello Andrei Popa,
Is there any way by which I can set the anchor position centre without changing the layer position in UI. and then make the anchor point back there, where it was.
-
Andrei Popa
August 9, 2018 at 7:17 amI don’t think you can. But you have some sort of workaround. Make a null, put it in the middle of your layer, parent your layer to it and apply the transformations you need to the null.
Andrei
My Envato portfolio.
Reply to this Discussion! Login or Sign Up
