Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Having elements track corners of text layer

  • Having elements track corners of text layer

    Posted by Maarten Lenoir on October 8, 2020 at 8:44 am

    I’m trying to get 2 rectangles to automatically follow the upper left and lower right corners of a text layer, using a “sourceRectAtTime()” expression.

    I managed to get each rectangle to go to their respective corners, but the moment the text layer starts moving, or text gets added/subtracted, the corners don’t follow properly.

    The expression for the top left rectangle is:

    src=thisComp.layer(“Quote”);

    w=src.sourceRectAtTime().width;

    h=src.sourceRectAtTime().height;

    l=src.sourceRectAtTime().left;

    t=src.sourceRectAtTime().top;

    [-(w+l),h+t]

    For the bottom right one:

    src=thisComp.layer(“Quote”);

    w=src.sourceRectAtTime().width;

    h=src.sourceRectAtTime().height*2;

    l=src.sourceRectAtTime().left;

    t=src.sourceRectAtTime().top;

    [w+l,h+t]

    I have uploaded the AEP file here, in case you want to have a look at it directly: https://www.dropbox.com/s/4dbsmr2ics64d08/cornertrack.aep?dl=0

    Stephen Dixon replied 5 years, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Stephen Dixon

    October 8, 2020 at 10:59 am

    The problem is that the sourceRectAtTime ecxpression is just giving you dimensions of the text box, not the positions of the text box in comp co-ordinates. Since the text dimensions don’t change when you move it, the boxes doesn’t follow.

    There are a couple of ways to get the comp position of the corners. The simplest, but least robust is to add the text box’s position to the expression, and subtract the shape layer’s position (this is in effect what would happen if you made the box layer the child of the text layer). So the last line could be

    [w+l, h+t]+src.transform.position - transform.position

    This won’t work if the text layer is scaled or rotated or is a child of another parent. That’s when you’d use layer space transforms. These translate coordinates to / from layer space from / to comp space. In this case you’d translate the coordinates of the text box into comp space, and then the comp space coordinates into the shape layer’s space. Layer space transforms are a little tricky to get your head around, but they’re very useful. So in this case you’d use this as the last line for the top left:

    fromComp(src.toComp([l,t]))

    This means “get the point on this layer over the point on the comp that is under the point [l, t] as seen from the text layer”

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