Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions A for loop inside an if statement inside a for loop = confusion

  • A for loop inside an if statement inside a for loop = confusion

    Posted by Madison Bullard on May 20, 2014 at 4:33 pm

    I’m trying to set up an expression that will allow me to place a bunch of layers in a grid, like tiles across the frame. I want the edges of the layers to touch. I’m assuming that I’m working with a 16:9 frame and all the layers are also 16:9.

    Apparently i’m going about this the wrong way, but I can’t figure out why this expression isn’t working. I’m sure it has to do with the fact that I’m not very confident with my Javascript skills.

    Any suggestions?

    *edit* The following expression gives me this:

    The first row works fine, after that each “row” starts cascading diagonally, stacking on top of each other in groups of 5.
    x=width*transform.scale[0]/200;
    y=height*transform.scale[0]/200;
    xOffset = 0;
    yOffset = 0;
    tilesPerRow = 5;

    for (i=0; i<=tilesPerRow; i++){ if (thisLayer.index/tilesPerRow > i && thisLayer.index/tilesPerRow <= i+1){ for(j=i*tilesPerRow+1; j0){
    yOffset += thisComp.layer(i).height*thisComp.layer(i).transform.scale[1]/100;
    }
    }
    }
    }

    [x+xOffset,y+yOffset]

    Madison Bullard replied 12 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    May 20, 2014 at 5:30 pm

    Assuming all layers are participating, I’d do something like this:

    titlesPerRow = 5;
    w = width*transform.scale[0]/100;
    h = height*transform.scale[1]/100;
    row = Math.floor((index-1)/titlesPerRow);
    col = (index-1)%titlesPerRow;
    [w,h]/2 + [col*w,row*h]

    Dan

  • Madison Bullard

    May 20, 2014 at 5:32 pm

    haha wow that is WAY simpler (and it works too!). Thanks, Dan.

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