Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Expression for anchor point position

Explorer ,
Feb 11, 2020 Feb 11, 2020

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

TOPICS
Expressions
10.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2020 Feb 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. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2020 Feb 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

 

scr.jpg

 

PS

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2020 Feb 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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2020 Feb 12, 2020

Thank you for your explaination Rick

It would help when I precompose my assests, but I'm sorry if the previous screenshot was misleading - I don't want to precompose every layer when I do that.

 

I'll give more information which might help -

Basically, I was trying to create my own in/out animation scripts using the transform effect.

I am trying to set the anchor to the bottom, animate it, and then save it as a script.

I want to apply this on random layers, and I don't want to precompose every such layer.

 

I hope that helps

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2020 Feb 12, 2020

Please show me the expression that is not working on an llustrator layer or a shape layer. I am still not clear why collapsing transformation on a vector layer will change for the anchor point is.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2020 Feb 12, 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:

Screenshot_2020-02-12 23.45.22_zZN0kJ.pngScreenshot_2020-02-12 23.46.24_LmpwJt.png

 

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

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2020 Feb 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2020 Feb 13, 2020

You can throw other expressions on Expression Control Sliders or Expression Point control then tie them to the other expressions and just use math to apply the values. If you use the expression controls you can modify any move after it is applied. It's by far more efficient than manually adding expressions to a bunch of layers. My last infographic/ dynamic text animation project was 12 minutes with a little more than 200 illustrations and text layers. I didn't have to manually create a single expression or set a single keyframe. The entire project of 30 comps, rendering and editing the final with a sound mix in Audition and final cut and polish in Premiere Pro + color grading took less than 10 hours. The artist creating the AI files took about 30 hours. That's how to work efficiently.

 

I really need to see a timeline with the modified properties of the layers involved showing so I understand. Nothing that you have described couldn't be done with an animation preset. I've made about 200 of them just for moving things around in the frame. None of them have keyframes, but most of them have sliders, angle controls, point controls, or color controls that are added to the layer as Effects. One-click, a couple of slider adjustments and my layers move in, then out and do all kinds of fancy things no matter what the layer scale is or what the source is. I don't use the Transform effect on any of them because if you Collapse Transformations you end up with the position and control points way out of position and there is no expression language method that I know of the will check for the CT switch so you could write an if/else statement to fix the problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2020 Feb 13, 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

 

scr.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 13, 2020 Feb 13, 2020

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2020 Feb 14, 2020

Roland,

Try replacing your expression with:

[width/2, height]

 

width and height always return the same value on vector layers as sourceRectAtTime(). 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 16, 2020 Feb 16, 2020
LATEST

Thank you, though this isn't helpful for other kind of layers.

I still haven't found a solution for that

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines