ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Dynamically center the anchor point of the individual shape in a shape layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Hiro Ober
Dynamically center the anchor point of the individual shape in a shape layer
on Apr 2, 2019 at 2:11:47 am
Last Edited By Hiro Ober on Apr 2, 2019 at 2:16:05 am

Hi guys,

I've searched around but didn't find too much information on this. Would really appreciate any help.

It's easy to dynamically anchor point for the whole shape layer, but is there any way to do it only for specific shape in a shape layer? Especially if it is not a regular shape like rectangle or circle, but a free hand-drawn path.

How do I get access to the data on the transform property on individual shape? Is it even possible? I know sourceRectAtTime works on shape layer, but it seems that it could only work on the whole shape layer, rather than the individual shape.

As you can see as below, I have a tail of the speech bubble drawn as a path in the shape layer(the triangle), and a rectangle as another shape in the same shape layer. Looking for a way to dynamically center the anchor point for the tail, so that it could dynamically change the position when I change the text.


Return to posts index

Scott Thomas
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 2, 2019 at 3:08:29 am

I've been working on some similar problems. So I'm making an attempt with your example.

The first thing I would do is get the anchor point to be in the center of the type and not on the baseline.

The code is for the anchor point for the type. We are taking the value for the width and height of the text and dividing each by half. Those two values are then added to the absolute left and top (0,0).

I'll post more as I figure things out.

var sourceRect = sourceRectAtTime(time);
[sourceRect.left + (sourceRect.width /2), sourceRect.top + (sourceRect.height / 2)]


Return to posts index

Hiro Ober
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 2, 2019 at 3:29:56 am

Thanks for the reply. But actually I don't have any problem of center anchor point of the text layer. The tricky thing is how to get property of the individual shape.


Return to posts index


Scott Thomas
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 2, 2019 at 5:52:59 am

I know. I'm trying to figure it out as well. Just wanted to make sure I was thorough. I spent some time on it tonight, but I finally decided to go home. I'll pick it up tomorrow.


Return to posts index

Scott Thomas
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 3, 2019 at 3:20:33 am

I think I may have something. I built the bubble the same way you did with the two separate shapes and the merge.

In addition to centering the anchor point of the type to its absolute center, I have master anchor point of the shape layer set to the position of the rectangle:

content("Rectangle 1").content("Rectangle Path 1").position

The text position expression brings in both the position of the entire shape layer and the position of the rectangle.

pos = thisComp.layer("Shape Layer 1").transform.position;

off = thisComp.layer("Shape Layer 1").content("Rectangle 1").transform.position;

[pos[0] + off[0] , pos[1] + off[1]]


"pos" named for the position, "off" for offset

13238_center.aep.zip

Is this what you were looking for?


Return to posts index

Scott Thomas
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 3, 2019 at 3:23:36 am

I just re-read the question. I see there is more to do. Sorry.
I'm trying. :)


Return to posts index


Tomas Bumbulevičius
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 3, 2019 at 11:20:04 am

Hey Hiro,

I don't think it is possible to access the size of individual shape inside the layer, simply because the sourceRectAtTime() function returns object from layers data source - and shape contents inside are not of layer type.

One thing to mention though - if you add sourceRectAtTime(time,true).width into text layer to inspect what width value of shape size it returns, and make turn shape object inside the layer as 'invisible', the size adjusts as expected (subtracting disabled shape value from the end result).

As a bit 'hardcoded' workaround, you could create two extra invisible/guide shape layers, which has individual shapes inside (one for tail, one for bubble). Then, find a way to connect positioning of those individual layers to group of shapes. While it might take a while for a first execution, once you make it - then re-usability is guaranteed. Definitely, not the most precious approach :)

Find out more:
After Effects Tutorials: motion design, expressions, scripting.


Return to posts index

Scott Thomas
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 9, 2019 at 3:49:44 am

I'm not sure how close I am to figuring out Hiro's question, but I attempted to do something that is probably closer to your suggestion. I'm forcing nearly everything to reference the top right corner of the rectangle. The text area resizes the rectangle and the tail just kind-of follows that.

13256_shapelayerproj.aep.zip



Scott Thomas


Return to posts index

Tomas Bumbulevičius
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 9, 2019 at 8:32:14 am

Scott, this seems like pretty much what was requested, nicely done !

Find out more:
After Effects Tutorials: motion design, expressions, scripting.


Return to posts index


Scott Thomas
Re: Dynamically center the anchor point of the individual shape in a shape layer
on Apr 11, 2019 at 5:02:25 am

Thank you. I've been working on some projects lately where I finally decided I needed to start learning expression to make things more consistent for TV promo editing. I have a lot to learn, but there is so much stuff out there to pull ideas from. I saw Hiro's question and thought it would be a good exercise to help in my education. :)


Return to posts index

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