Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Dynamically center the anchor point of the individual shape in a shape layer

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

    Posted by Hiro Ober on April 2, 2019 at 2:11 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.

    Scott Thomas replied 5 years, 9 months ago 3 Members · 9 Replies
  • 9 Replies
  • Scott Thomas

    April 2, 2019 at 3:08 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)]

  • Hiro Ober

    April 2, 2019 at 3:29 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.

  • Scott Thomas

    April 2, 2019 at 5:52 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.

  • Scott Thomas

    April 3, 2019 at 3:20 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?

  • Scott Thomas

    April 3, 2019 at 3:23 am

    I just re-read the question. I see there is more to do. Sorry.
    I’m trying. 🙂

  • Tomas Bumbulevičius

    April 3, 2019 at 11:20 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.

  • Scott Thomas

    April 9, 2019 at 3:49 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

  • Tomas Bumbulevičius

    April 9, 2019 at 8:32 am

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

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

  • Scott Thomas

    April 11, 2019 at 5:02 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. 🙂

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy