FORUMS: list search recent posts

Shape Layer Anchor Point & Scaling

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Eli Coogan
Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 4:51:06 am

Trying to use expressions on a shape layer's position, which acts as an anchor point when adjusting size (since anchor points don't seem to effect a shape layer's scaling center).



As you can see in the photo, I'm trying to add two expression controllers. One controls how wide the rectangle is, the other controls the anchor point being justified left or right on the rectangle.

That's working fine, but I can't figure out how to get the rectangle to remain in the same position when I select/deselect the checkbox. I assumed it would be something like:

WidSize = content("Rectangle 1").content("Rectangle Path 1").size[0];
HeightSize= content("Rectangle 1").content("Rectangle Path 1").size[1];

if (effect("AnchorLeft")("Checkbox")==1) [WidSize/2- WidSize,HeightSize] else [WidSize/-2,HeightSize]


But that is not working. I felt like I was on the right path because when I change it to:

WidSize = content("Rectangle 1").content("Rectangle Path 1").size[0];
HeightSize= content("Rectangle 1").content("Rectangle Path 1").size[1];

if (effect("AnchorLeft")("Checkbox")==1) [WidSize/2- 500,HeightSize] else [WidSize/-2,HeightSize]


It then appears to stay in the same position. How do I subtract that width value?

Thank you,
Colton


Return to posts index

Scott McGee
Re: Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 8:44:03 am

I do something similar but using a sourceText rather than a checkbox, so I'm hoping the bits I've changed in the below expression works.

I use the size of the shape, so if I change the size (Not scale, but I've not tried it with scale) and position, it should work everytime.

anchor point:

R = thisLayer.sourceRectAtTime(time);
I = thisComp.layer("[Anchor]").text.sourceText.toLowerCase();
T = R.top;
L = R.left;
W = R.width;
H = R.height;

if (effect("AnchorLeft")("Checkbox")==1) [L,T] else [W/2,T]


position:

if (effect("AnchorLeft")("Checkbox")==1)
[transform.position[0] - content("Rectangle 1").content("Rectangle Path 1").size[0],transform.position[1]]
else
[transform.position[0],transform.position[1]];


Return to posts index

Eli Coogan
Re: Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 4:44:21 pm

Thanks for your response, Scott!

That seems very interesting. However, I may be doing something wrong-- what is this variable for?
I = thisComp.layer("[Anchor]").text.sourceText.toLowerCase();

Do you add an additional layer named anchor?

The anchor position swapping works great, but I'm still having the problem of the line jumping when I use the checkbox.

Thanks again, I'm trying to get a better grasp of this.


Return to posts index


Scott McGee
Re: Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 5:52:53 pm

I accidentally left that in from my expression I use, that might have been the reason why it wasn't working, if it was flagging it as an error it might not work.

So try using this again, with that line you messaged removed.


Anchor Point:

R = thisLayer.sourceRectAtTime(time);
T = R.top;
L = R.left;
W = R.width;
H = R.height;

if (effect("AnchorLeft")("Checkbox")==1) [L,T] else [W/2,T]

position:

if (effect("AnchorLeft")("Checkbox")==1)
[transform.position[0] - content("Rectangle 1").content("Rectangle Path 1").size[0],transform.position[1]]
else
[transform.position[0],transform.position[1]];


Return to posts index

Scott McGee
Re: Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 6:11:02 pm

Just to double check, as I've noticed you are using an expression in yours for how you used to cheat the anchorpoint on a shape layer pre cs6 before sourceRectAtTime was introduced.

Do you have cs6 or above. As my expression won't work?

If you do...

number 2 are you putting the position expression in the transform Position or rectangle position.

My expression needs to go into transform, not as you have it in your example you gave.

See if that works aswell.


Return to posts index

Scott McGee
Re: Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 9:02:19 pm

Alternatively, if anyone is using cs5.5 or lower like I do at home.

I got your method of doing it to work Eli

If you put this expression into the shape position.

content("Rectangle 1").content("Rectangle Path 1").size/2;


and this, into the Transform:Rectangle AnchorPoint (not to be mistaken for the normal anchor point in transform) (I accidentally did the expression to work based on the right...Just swap it round if you want left)

if (effect("AnchorRight")("Checkbox") == 1)
[content("Rectangle 1").content("Rectangle Path 1").size[0],0]
else
[0,0]


Then in the Transform Position add this.

if (effect("AnchorRight")("Checkbox") == 1)
transform.anchorPoint
else
[transform.anchorPoint[0]+content("Rectangle 1").content("Rectangle Path 1").size[0],transform.anchorPoint[1]]


Essentially the top two bits are determining are cheating to find the left and right top corners, but it's moving the shape. So the third expression is just counteracting the top to so it remains in the same spot.


Return to posts index


Eli Coogan
Re: Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 9:31:05 pm

Hey Scott,

Thanks for all the info! I just tried your code, but am still getting the position jump. Can't figure it out... I must be doing something wrong.

(with checkmark on)


(with checkmark off)



I'll keep playing around with it though. I really do appreciate your time!

Thanks.


Return to posts index

Scott McGee
Re: Shape Layer Anchor Point & Scaling
on Aug 4, 2017 at 11:29:07 pm

Hey Eli,

In you image. 4 items up it says position. It's that position you need to add the third expression.

The position you've added it to disrupts the way the other two expressions cheat the anchor point to be in the top left and right corner.


Return to posts index

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