Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to make one shape mimic another’s scale & position?

  • Expression to make one shape mimic another’s scale & position?

    Posted by Henry Acteson on January 23, 2018 at 3:14 am

    Okay so I make templates to be used in after effects through the use of Dataclay so one of the big factors in what I do is making sure things stay uniform as information and values within the projects are adjusted before exporting. The desired animation I am creating is illustrated in the gif below, now my dilemma arises when I try to get the coloured boxes to adjust scale and position along with their black foreground counterparts.

    Gif of animation:

    Here is what I am currently working with in terms of expressions-

    To adjust black box size:
    The first expression needs to be applied to the shape layers position:

    t = thisComp.layer(“my_text”);
    tRect = t.sourceRectAtTime(time,false);
    tUL = t.toComp([tRect.left,tRect.top]);
    tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
    tCenter = (tUL + tLR)/2
    myRect = sourceRectAtTime(time,false);
    myUL = toComp([myRect.left,myRect.top]);
    myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
    myCenter = (myUL + myLR)/2
    delta = myCenter – tCenter;
    value – delta

    This expression needs to be applied to the shapes scale within the shape itself’s transform options for scale. Rectangle 1 > Rectangle 1 Path > Size. In my first test I also applied this expression to the shape layers scale:

    t = thisComp.layer(“my_text”);
    tRect = t.sourceRectAtTime(time,false);
    tUL = t.toComp([tRect.left,tRect.top]);
    tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
    myRect = sourceRectAtTime(time,false);
    myUL = toComp([myRect.left,myRect.top]);
    myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
    margin = 10;
    [(tLR[0]-tUL[0] + 2*margin)/(myLR[0]-myUL[0]),(tLR[1]-tUL[1]+ 2*margin)/(myLR[1]-myUL[1])]*100

    And my expression to control the coloured boxes behind which are referencing an adjustment layer with Slider Control. They have both the size adjustment expressions as well as this expression:
    wiggle(10, thisComp.layer(“Slider 1”).effect(“Slider Control”)(“Slider”))

    I’ve been using after effects professionally since March of 2017 and largely learnt much of this from this site. It is my first time posting so please let me know if I have left out any necessary information. I should also note that the actual desired template only has single lines of text.

    t = thisComp.layer("my_text");
    tRect = t.sourceRectAtTime(time,false);
    tUL = t.toComp([tRect.left,tRect.top]);
    tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
    tCenter = (tUL + tLR)/2
    myRect = sourceRectAtTime(time,false);
    myUL = toComp([myRect.left,myRect.top]);
    myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
    myCenter = (myUL + myLR)/2
    delta = myCenter - tCenter;
    value - delta
    wiggle(10, thisComp.layer("Slider 1").effect("Slider Control")("Slider"))

    Henry Acteson replied 8 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    January 23, 2018 at 9:32 am

    So i guess what you are saying is that you want to use wiggle plus the position expression for the coloured rectangles. You can not have two values for an expression. After effects just takes the last value. So the first thing that came to mind was to add the wiggle to the expression on the previous line. Did that, but it moved the shape out of my screen. Wondering why it did that, i tried figuring how wiggle works. So aparently wiggle takes the raw value of the position and plays with them. Just substract the position value at the end. It seems to work. So the whole expression would be this.
    t = thisComp.layer("my_text");
    tRect = t.sourceRectAtTime(time,false);
    tUL = t.toComp([tRect.left,tRect.top]);
    tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
    tCenter = (tUL + tLR)/2
    myRect = sourceRectAtTime(time,false);
    myUL = toComp([myRect.left,myRect.top]);
    myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
    myCenter = (myUL + myLR)/2
    delta = myCenter - tCenter;
    value - delta+wiggle(10, thisComp.layer("Slider 1").effect("Slider Control")("Slider"))-transform.position

    Andrei
    My Envato portfolio.

  • Henry Acteson

    January 23, 2018 at 10:18 pm

    Andrei,

    Thank you ver much for helping me out with this. That new expression has fixed my issue.

    Regards,
    Henry

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