Skip to main content
Inspiring
February 11, 2020
Question

Expression for anchor point position

  • February 11, 2020
  • 2 replies
  • 11137 views

I'm trying to come up with an expression that will center the anchor point of a transform effect at the bottom.

I did find such an expression, but it's completely messed up if I turn on continuously rasterize:

a = thisLayer.sourceRectAtTime();
height = a.height;
width = a.width;
top = a.top;
left = a.left;
x = left + width/2;
y = height;
[x,y];

Is there any adjustment I can do to fix it to working when continuously rasterize is on?

Thank you

2 replies

Community Expert
February 13, 2020

I think I understand your problem. When you apply CR to a vector layer the layer size changes from layer size to comp size. For example, I have a Vector layer named Nancy. The layer size is 154, 457. That puts the anchor point at 77, 228.5. If I turn on collapse transformations the layer size changes to the comp size so if you are working in a standard HD comp the new layer size is 1920, 1080 and the Anchor Point is now 960, 540. 

 

When you write an expression for a vector layer and you use just height and width it always reports the original layer size. In other words, both of these expressions added to Anchor Point will give you the same result, a Vector layer with the Anchor point at the center of the layer on the bottom of the layer. 

[width/2, height]

// same as 

a = thisLayer.sourceRectAtTime();
[a.width/2, a.height]

There is no need to mess with sourceRectAtTime() to make your expression work. 

 

The problem comes when you apply the expression to the Transform>Anchor Point property instead of the Anchor Point property. Open up the timeline and see what happens to both the Transform>Anchor Point and the Transform>Position property with you Collapse Transformations. Compare that with Anchor Point and Position for the layer. 

 

I have a bunch of automatically animated moves driven entirely by expressions so I can very quickly create infographic and dynamic text animations. None of them use the Transform effect because of this problem. They all work with the layer/transform properties.

 

If you want to use Transform to reposition content of the layer while keeping the Layer>Anchor Point at the center of the bottom of the layer add these two expressions as indicated:

[width/2, height]; // for Transform Anchor Point

[width, height]/2;  // for Transform Position

This will keep the layer from moving when you Collapse Transformations. The only problem is that the new position and Anchor Point centers for the Transform Effect will not be centered on the layer any more so you can't use the Transform>Rotation or Transform/Skew when CT is turned on. This is what I mean:

 

So unless you absolutely have to use the Transform effect I suggest that you just work with the layer's anchor point and position property. 

 

You might want to take a look at this animation preset that I have created for a layer. All you have to do is position the layer where you want it to land, set the in and out points, and the layer will fly in from the left, bounce to a stop and then fall off the bottom of the screen just before the out point of the layer. It's one of my most used animation presets. Enjoy:

https://www.dropbox.com/s/tewk9s88mpkmnou/flyInBounceDropOut.ffx?dl=0

 

 

Guym20Author
Inspiring
February 13, 2020

Thank you so much Rick

I understand the problem with using the Transform effect and I did consider using the position and scale properties of the layer.

However, I don't want the preset to write expressions on these properties, because I want to add my own expressions later on (for example - wiggle), which can cause a problem.

I'm not sure how to do that without using expression, because if I just use keyframes to slide the object to its position - I don't know how to make it slide into the original position where it was before applying the preset.

 

Is there any way around that?

Roland Kahlenberg
Legend
February 14, 2020

Rick, I'm not sure what else to show so you can understand my needs better.

I simply want to create multiple presets for animations, exactly like you did, but I don't want to use expressions for it.

When you're using expressions for that - how can you later on add more expressions to the movements? Wiggle, for example.

Also, writing such long expressions is much more complicated and time consuming than animating keyframes and save them.

 

I'm attaching a simple screenshot, maybe it'll help

 


Too late and too much into the mix but seems like attaching your layer to a parent Null Object might work.

 

You should also use this Expression in place of the one you are using -

a = thisLayer.sourceRectAtTime();
height = a.height;
width = a.width;
top = a.top;
left = a.left;
x = left + width/2;
y = top + height;
[x,y];

-------------------------------------

This Expression works for Text and Shape Layers and these are indeed Continuously Rasterized, inherently.

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
Community Expert
February 11, 2020

From the User Guide:

sourceRectAtTime(t = time, includeExtents = false)
Return type: JavaScript object with four attributes: [top, left, width, height]. Extents apply only to shape layers, increasing the size of the layer bounds as necessary, and paragraph text layers (After Effects 15.1 and later), where it returns the bounds of the paragraph box. Example: myTextLayer.sourceRectAtTime().width.

 

If you add your expression to the Anchor Point of a shape layer it will not move the anchor point to the middle and bottom of the shape. It won't work because the Anchor Point of a shape layer is at 0, 0. The width and height of a shape layer is the same as the comp size and width.

 

Add your expression to the Anchor Point a text layer and the anchor point will end up below the baseline of the text by the height of the characters. You'll have to adjust the baseline shift to move the anchor point to the bottom of the last line of text. 

 

There is no need for all of the sourceRectAtTime() business if you want to move the Anchor Point of any other type of layer to the bottom center of the layer. All you need is [width/2, height]

 

Turning collapse transformations on changes the layer size if you have a layer that is smaller than the comp size. If you have a 200 X 200 solid in a standard HD comp and you pre-compose the new size of the layer is 1920 X 1080 (HD), so either expression would put the anchor point at the bottom center of the layer. Turning on Collapse Transformations would move the layer controls from the outside of the layer to the size of the solid, but the anchor point would not change and the solid would not move.

 

When you throw the Effects>Distort>Transform effect on a layer the effect is applied before the layer transforms are applied. There should be no change in position when you collapse transformations, but the expression will compound the movement of the layer so the new transform value will be off by the layer height and width. 

 

I will have to see your timeline with the modified properties of the layer that is giving you problems revealed and I'll need to understand exactly what you are trying to do to help. It kind of sounds like you are attempting to use the Transform Effect to position the anchor point of a layer at the bottom of the visible pixels. 

 

Guym20Author
Inspiring
February 11, 2020

Hi Rick

Thank you for the detailed answer

Yes - I'm trying to add a transform effect and set its anchor (using expressions) at the bottom of the visible layer, no matter what kind of layer it is, whle allowing me to enable "collapse transform".

Here is a screenshot

 

 

PS

I would then write an expression that will position the element back to its original position after the anchor has changed

Community Expert
February 11, 2020

When you pre-compose a layer the new layer size will be the size of the comp. If there is a shape layer or an AI file in that pre-comp then you'll have to have the expression reference the layer in the pre-comp, not the layer in the existing comp. Then all you need to do to keep the anchor point at the bottom of the AI file is add half the height of the layer.  If the pre-comp was called Pre-comp 1 and your AI layer was named Vector Layer 1 then your expression for anchor point would look like this:

a = comp("Pre-comp 1").layer("Vector Layer 1").sourceRectAtTime();
yShift = a.height/2;
[width/2, yShift + value[1]]

That will keep the layer from moving when you collapse transformations and center the anchor point on the bottom of the pre-composed (nested) vector layer as long as the vector layer in the pre-comp is in the center of the comp.

 

Things are going to get a lot more complicated if you start moving the layer around in the pre-comp. You will have to reference the position of the layer in the pre-comp and subtract that from the anchor point in order to keep the vector layer in the same position. As long as the layers are centered in the Pre-comp and the anchor point of the layer is in the center of the pre-comp, your anchor point will always be at the bottom of the visible pixels in the main comp.