Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scaling up affects position of neighbor layers (avoid overlap)

  • Scaling up affects position of neighbor layers (avoid overlap)

    Posted by Jason Jantzen on July 16, 2013 at 12:08 am

    I have 5 layers in the center of my comp aligned horizontally and distributed evenly. What I’d like to do is scale up 3 layers at a time, could be 3 neighboring layers scaling up or skipping one – so like this pattern –

    XxXXx
    XXXxx
    XxXxX

    that sort of thing. the problem is when they scale up I have to manually keyframe position to avoid overlapping or just not scale them very much. I’d like to scale them more than what I’m limited by overlapping for design reasons, so I’m wondering if there’s a way to tell the position parameter to look at the layer’s boundaries and not collide or overlap with the neighboring layers when they scale up.

    Jason Jantzen
    vimeo.com/jasonj

    Philip Ames replied 11 years, 11 months ago 4 Members · 14 Replies
  • 14 Replies
  • Mitch Mann

    July 16, 2013 at 2:39 pm

    You could probably do something like this with Newton 2.

    https://motionboutique.com/newton/

    Keyframing sounds like a good solution, the math sounds tricky. For starters, I guess the distance between any two objects would need to be something like:

    Distance between Objects A & B = ( (Object A’s width / 2) * (Object A’s scale) ) + ( (Object B’s width / 2) * (Object B’s scale) )

  • Jason Jantzen

    July 16, 2013 at 3:30 pm

    I know what you’re thinking with the distance joints and all that, but Newton doesn’t use animated scale. I tried just now to confirm my suspicions using aematic and kinematic, and even dynamic even though I knew it wouldn’t do anything.

    I wish I could write a basic expression like you’re suggesting that works. I thought what you had written there was a functioning expression, but it doesn’t seem to work, just throws an error. Thanks tho 🙂

    Jason Jantzen
    vimeo.com/jasonj

  • Mitch Mann

    July 16, 2013 at 5:43 pm

    If you used Newton I guess you’d link the scale to other attributes with an expression, rather than hoping Newton would do it all automatically. Yeah, my post was to help you to think through your creation of an expression that might work for you, I haven’t done all the work for you there.

  • Dan Ebberts

    July 16, 2013 at 7:37 pm

    This may not be exactly what you’re looking for, but it should give you some ideas. It assumes that there are 5 layers participating, that they are the first 5 layers in the layer stack, there is a 10 pixel gap maintained between layers, and the result is centered on the comp’s center line:


    numLayers = 5;
    gap = 10;
    totalWidth = 0;

    for (var i = 1; i <= numLayers; i++){
    L = thisComp.layer(i);
    totalWidth += L.width*L.scale[0]/100;
    if (i < numLayers) totalWidth += gap;
    }

    myX = width*scale[0]/200;

    for (var i = 1; i < index; i++){
    L = thisComp.layer(i);
    myX += L.width*L.scale[0]/100 + gap;
    }

    [(thisComp.width - totalWidth)/2 + myX,value[1]]

    Dan

  • Jason Jantzen

    July 16, 2013 at 10:46 pm

    I knew you’d figure something out, Dan! Thanks a million. It works perfect!

    Jason Jantzen
    vimeo.com/jasonj

  • Philip Ames

    June 5, 2014 at 10:02 pm

    this is a huge help, Mr Ebberts, and works like a charm. thank you.

    i was wondering, though, if you’d have a moment (or the inclination) to break this apart. i’m trying to make this work on the Y axis and, eventually, on the X and Y together, and it might help if i understood better where the axis are controlled from.

    many thanks in anticipation

  • Dan Ebberts

    June 5, 2014 at 10:53 pm

    This should work for y:

    numLayers = 5;
    gap = 10;
    totalHeight = 0;
    for (var i = 1; i <= numLayers; i++){
    L = thisComp.layer(i);
    totalHeight += L.height*L.scale[1]/100;
    if (i < numLayers) totalHeight += gap;
    }
    myY = height*scale[1]/200;
    for (var i = 1; i < index; i++){
    L = thisComp.layer(i);
    myY += L.height*L.scale[1]/100 + gap;
    }
    [value[0], (thisComp.height - totalHeight)/2 + myY]

    And this should work for both:


    numLayers = 5;
    gap = 10;
    totalWidth = 0;
    totalHeight = 0;
    for (var i = 1; i <= numLayers; i++){
    L = thisComp.layer(i);
    totalWidth += L.width*L.scale[0]/100;
    totalHeight += L.height*L.scale[1]/100;
    if (i < numLayers){
    totalWidth += gap;
    totalHeight += gap;
    }
    }
    myX = width*scale[0]/200;
    myY = height*scale[1]/200;
    for (var i = 1; i < index; i++){
    L = thisComp.layer(i);
    myX += L.width*L.scale[0]/100 + gap;
    myY += L.height*L.scale[1]/100 + gap;
    }
    [(thisComp.width - totalWidth)/2 + myX, (thisComp.height - totalHeight)/2 + myY]

    Dan

  • Philip Ames

    June 6, 2014 at 1:20 pm

    phenomenal, thank you. still poring over the X&Y version, as it’s currently setting up a 3×3 (*edited*) grid in a diagonal line. trying to figure out why. and trying by myself lol

    can i ask, in the X vs Y set up, why the “value” difference in the last line? is the placement significant?

    X axis version - [(thisComp.width - totalWidth)/2 + myX,value[1]]
    Y axis version - [value[0], (thisComp.height - totalHeight)/2 + myY]

  • Dan Ebberts

    June 6, 2014 at 4:31 pm

    In the x version, value[0] refers to the x component of the pre-expression position. In the y version value[1] refers to the y component. The final result is in the form [(new x value),(new y value)], so yes, placement does matter.

    Dan

  • Philip Ames

    June 10, 2014 at 6:18 pm

    ouch, that was so obvious it actually hurt. thank you.

    i hope it isn’t a huge suck on your time if i ask you why the script might, when applied to my 3×3 grid (9 layers), it rearranges the 9 blocks into a diagonal line, starting at (-168 x,-448 y to 1448 x,1168 y)? in fact, if i just use 3 layers, it makes the blocks line up diagonally too.

    thanks in advance

Page 1 of 2

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