Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Box shape defined by 2 corner points?

  • Box shape defined by 2 corner points?

    Posted by Phil Aupperle on February 24, 2016 at 9:26 pm

    I’ve checked out the “Scaling and Rotating a Shape between two points” thread, and I’ve used the sourceRectAtTime technique to build dynamic text boxes, but I have a slightly different problem now: I’m trying to make an expression that will simply draw a shape layer rectangle that is defined by the positions of two nulls on opposite corners. That way, I can attach other things to the nulls, keyframe, position and size the box by just dragging the corners like a window on a computer, etc. It seems super useful.

    Any thoughts/ideas?

    Thanks!!

    Phil Aupperle replied 10 years, 5 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    February 24, 2016 at 10:43 pm

    Play around with this.

    1. Create a rectangular shape layer.
    2. Add Null 1 where you want the upper left corner.
    3. Add Null 2 where you want the lower right corner.

    4. Add this to the Rectangle Path’s Size parameter:

    n1 = thisComp.layer(“Null 1”);
    n2 = thisComp.layer(“Null 2”);
    ul = n1.toComp(n1.anchorPoint);
    lr = n2.toComp(n2.anchorPoint);
    d = lr -ul;
    [Math.abs(d[0]),Math.abs(d[1])]

    5. Add this to the Rectangle Path’s Position parameter:

    n1 = thisComp.layer(“Null 1”);
    ul = n1.toComp(n1.anchorPoint);
    r = sourceRectAtTime(time,false);
    myUL = toComp([r.left,r.top]);
    ul – myUL

    You’ll need additional code if it’s possible that Null 1 can become something other than the upper left corner relative to Null 2.

    Dan

  • Phil Aupperle

    February 24, 2016 at 11:40 pm

    Awesome! Thank you. Works perfectly.

    I could get the size correct in my attempts, but the position was making me insane. I’ll admit I don’t understand the implementation of shape and path sizes/positions/anchor points in shape layers relative to normal layer parameters and comp coordinates at all, apparently, and I get totally lost in the vectors. Is the position of a path the center of it’s bounds, or does it have some default anchor point? Are a path’s coordinates based on the shape layer anchor point and position? If you happen to know where in the Adobe documentation this is, I’d love to get up to speed on it.

    Thanks again for the help–this is something I can think of a million uses for. You are the man.

  • Dan Ebberts

    February 25, 2016 at 12:34 am

    I wish I could say I had it all figured out. It seems to be a affected by position, anchor point and scale and I usually just work it out based on the current requirements. I don’t know of any definitive documentation on the subject, but I would welcome it.

    Dan

  • Phil Aupperle

    February 25, 2016 at 12:40 am

    Oh man! Well, that makes me feel a little better anyway. Hopefully someone from the Adobe team is reading this. 😉

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