ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Attach anchorpoint to the center of the layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Rainier Raydán
Attach anchorpoint to the center of the layer
on Aug 16, 2017 at 3:02:45 pm

Hi! 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!


Return to posts index

Andrei Popa
Re: Attach anchorpoint to the center of the layer
on Aug 16, 2017 at 3:14:14 pm

The 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


Return to posts index

Rainier Raydán
Re: Attach anchorpoint to the center of the layer
on Aug 16, 2017 at 3:28:12 pm

WOW! thank you so much! Works like a charm 😊


Return to posts index


Rainier Raydán
Re: Attach anchorpoint to the center of the layer
on Aug 24, 2017 at 1:58:55 pm

Sorry, do you have any idea on how to set the anchor point to upper right or left, center right or left and so?


Return to posts index

Andrei Popa
Re: Attach anchorpoint to the center of the layer
on Aug 24, 2017 at 3:30:37 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


Return to posts index

Rainier Raydán
Re: Attach anchorpoint to the center of the layer
on Aug 24, 2017 at 3:49:54 pm

Thanks!


Return to posts index

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