Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Auto-position type layers using bounding box?

  • Auto-position type layers using bounding box?

    Posted by Casey Drogin on February 7, 2022 at 9:21 pm

    Hi there,

    I’m building a toolkit with some simple type. I’d like to have the TOP LINE and the BOTTOM LINE maintain a distance of exactly 75 pixels from the HERO TYPE layer. So that, when retyping the HERO type, if it is one, two, three or four lines tall then the TOP / BOTTOM will always maintain the same distance.

    However, I’m having trouble getting anything to work. I’ve found a lot of stuff online about bounding boxes, but having trouble converting that over to these. Does anyone have any recommendations?

    Thank you!

    Casey Drogin replied 4 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    February 8, 2022 at 10:37 am

    I would do this in the following way:

    AnchorPoint expression for the top layer

    var myWidth = sourceRectAtTime(sourceTime(0),false).width;
    var left = sourceRectAtTime(sourceTime(0),false).left;
    var myHeight = sourceRectAtTime(sourceTime(0),false).height;
    var top = sourceRectAtTime(sourceTime(0),false).top;
    [left+myWidth/2,myHeight+top]

    AnchorPoint expression for the bottom layer

    var myWidth = sourceRectAtTime(sourceTime(0),false).width;
    var left = sourceRectAtTime(sourceTime(0),false).left;
    var top = sourceRectAtTime(sourceTime(0),false).top;
    [left+myWidth/2,top]

    AnchorPoint expression for the mid layer

    var myWidth = sourceRectAtTime(sourceTime(0),false).width;
    var left = sourceRectAtTime(sourceTime(0),false).left;
    var myHeight = sourceRectAtTime(sourceTime(0),false).height;
    var top = sourceRectAtTime(sourceTime(0),false).top;
    [left+myWidth/2,myHeight/2+top]

    Position for top

    L = thisComp.layer(index+1);
    H = L.sourceRectAtTime(0,false).height;
    diff = 75;
    S = L.scale[1];
    P = L.position;
    [value[0], P[1] - diff - S * H * 0.005]

    Position for bottom

    L = thisComp.layer(index-1);
    H = L.sourceRectAtTime(0,false).height;
    diff = 75;
    S = L.scale[1];
    P = L.position;
    [value[0], P[1] + diff + S * H * 0.005]

    What we have done is:

    Put anchor point of the top layer to its bottom.

    Put anchor point of the bottom layer to its top.

    Put anchor point of mid layer in its mid.

    We have done these to have an easier position expression.

    The position of the top layer is the position of the mid minus half of it’s height minus your difference. We multiplied this by scale*0.01, because sourceRectAtTime does not include the scale in it’s value. So that 0.005 is just the 0.01 from scale multiplied with the 0.5 from height.

    Same for the bottom layer, but with plus instead of minus.

    You should take in consideration that these layers are in order in timeline: top, mid, bottom. If you have a different order, you should link your mid layer in both position expressions, on the first row. So instead of L = thisComp.layer(index-1); you will have something like L = thisComp.layer(“HERO TYPE”);

  • Casey Drogin

    February 8, 2022 at 3:54 pm

    Andrei – don’t know how to thank you enough. This worked like a charm! Really and truly appreciate your help – learned a lot going through this!

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