Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adressing Nth Layer

  • Adressing Nth Layer

    Posted by Andy Kreutzberg on February 19, 2013 at 4:32 pm

    Hello all,

    here is a little problem i am trying to figure out. I am trying to built a self arranging text arrangement. The first layer sits on the left, the second layer in the middle and the third layer on the right side of the screen. The fourth layer would sit on the exact same position as the first layer, the fifth on the position of the second, the sixth on the position of the third and repeating this pattern.

    Thing is, this must be dynamic. Say, if i only have layer 1, it should sit on the left. If i duplicate this exact layer (creates a total of 2), it should move to the middle of the screen. If i duplicate any of those two layers (creates a total of 3), it should move to the right. If i duplicate any of these yet again (a total of 4) it should move to the position of the first layer, meaning left side.

    I kind of managed to create a code for the position offset.

    z1=thisLayer.index-7;
    z2=z1*2
    x1=transform.position[0];
    x2=transform.position[1];
    if(z1<2)
    {[x1,x2]};
    else
    {[x1*z2,x2]};

    However, this will only keep offsetting the position for each additional layer. I wonder if there is a way to have every 4th duplicated layer snap back to the position of the 1st layer.

    Sorry if this is confusing, but i hope you guys can help me out.

    Andy Kreutzberg replied 13 years, 2 months ago 3 Members · 3 Replies
  • 3 Replies
  • Jamie Bradshaw

    February 19, 2013 at 4:41 pm

    If I understand you correctly then you might need to use the % operator.

    So if n is your layer number then n%3 will give you a number of 0, 1 or 2.

    For example if:

    n = 1 then n%3 = 1
    n = 2 then n%3 = 2
    n = 3 then n%3 = 0
    n = 4 then n%3 = 1
    n = 5 then n%3 = 2
    n = 6 then n%3 = 0
    ..and so on

    Does that help?

    JimJam•Graphics
    https://www.jimjamgraphics.com/

  • Dan Ebberts

    February 19, 2013 at 4:42 pm

    If you define your 3 x positions in the xPos array in the first line, something like this should work:

    xPos = [0,thisComp.width/2,thisComp.width];
    myX = xPos[(index-1)%3];
    [myX,value[1]]

    Dan

  • Andy Kreutzberg

    February 20, 2013 at 10:28 am

    Guys, you helped me out again! I never used the modulus % operator before. Did some research now after i saw your expression and this seems to do the trick. Works like a charm. Also, in dan’s expression the array with the three values works nicely. At first, i was a bit confused about the comp.width thing but i just replaced it with [200, 750, 1300] which is the exact positions for the layers. It’s amazing. Thanks again!

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