Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Grid expression…..sort of.

  • Grid expression…..sort of.

    Posted by Eric Sanderson on September 26, 2012 at 7:07 pm

    Ive come close to getting this to work but its becoming a mess so thought id find a clean accurate way to make it happen. I have a grid of tiles, but im really only worried about affecting the rows, along x. So that if i need to change the size (actual comp size) of one of the tiles, o replace the comp with a different size (one of 4 or so predetermined sizes) the rest of the tiles contract or expand along xPos accordingly. They all have a 4 pixel Gap which ive attached to a slider called xSpread on a “controller” null. Any help would be great, thanks

    the first (very left) tile in each row is the master, index-1 the rest in the row until the first tile in the next row.

    layer.width = 236 at the smallest, and can be as large as 236*5

    Dan Ebberts replied 13 years, 7 months ago 2 Members · 11 Replies
  • 11 Replies
  • Dan Ebberts

    September 26, 2012 at 8:33 pm

    This is not exactly what you’re asking for, but it might help. It assumes the top layer in the layer stack is the upper left corner of the grid:


    gap =thisComp.layer("controller").effect("gap")("Slider");
    idx = 1;
    wMax = thisComp.width;
    row = 0;
    w = 0;
    while (idx < index){
    w += thisComp.layer(idx).width + gap;
    if (w > wMax){
    row++;
    w = 0;
    }
    idx++
    }
    y = row*height + height/2 + row*gap;
    x = w + width/2;
    [x,y]

    Dan

  • Eric Sanderson

    September 26, 2012 at 9:46 pm

    Not able to get it really working for me, shouldve mentioned ive separated dimensions since im just focused on the X so i just got rid of the “y” stuff and the array, that parts not a big deal. What i had “almost” working was what was turning out to be a huge stack of “if else if” statements, at which point i thought thered be a better way. My conditions were as follows, not written in actual code obviously:

    (just using 2 different sizes for the example for simplicity sake)

    If thisLayer.width is 236 && index-1 layer.width is 236, xPos+236 (or maybe even thisLayer.width)+gap

    else if thisLayer.width is 236 && index-1 layer.width is 476, xPos+236*1.5+4 (this 4 is because the 476 size is the size of 2 236 tiles side by side including the gap)+gap…

    ….and then visa versa and every combination of the 2 (or what in my real case would be every combination of 4 or 5 size variables), this ends up being a long list of if else if’s. Ill just go back to doing that for now unless theres a painfully obvious simpler way, i cant follow your previous code enough to rig it into what i need.

  • Dan Ebberts

    September 26, 2012 at 10:06 pm

    It should be a fairly simple loop, but the expression has to know the index of the first layer in its row. Then it just loops through those layers, adding up the width (plus gaps). After the loop it adds half its own width to the result to end up with its x position. Something like this:


    startIndex = 1;
    gap = 4;
    w = 0;
    for (i = startIndex; i < index; i++){
    w += thisComp.layer(i).width + gap;
    }
    w + width/2

    Dan

  • Eric Sanderson

    September 27, 2012 at 4:30 pm

    Yesss. Threw me off a little at first until i realized you needed the code on the master layer and that it snapped it to the 0 of the comp, but i can definitely work with that. This is going to save me maaany hours over the next few months, i owe you a donation. Would like to dive into how that works, i recognize and for the most part understand the meaning of each individual thing thats there, how its actually working is a little beyond me though. Thanks again.

  • Dan Ebberts

    September 27, 2012 at 5:06 pm

    Glad I could help. Please shoot me an email through my web site. I tried to respond to your query, but the message keeps bouncing back.

    Dan

  • Eric Sanderson

    October 1, 2012 at 7:07 pm

    How hard would this be to modify to reference the scale[0] instead of width, but still move the amount of width. I took a few stabs at it, combination of simply swapping out the .width for scale[0] in the code, which obviously resulted in moving my tiles from 0-100, so figured from there i could simply linear the whole result, with thisLayer.width being the upper output, buuuut thats doing nothing for me. Am i close? lol.

  • Dan Ebberts

    October 1, 2012 at 7:35 pm

    I’m guessing this is what you’re looking for:


    startIndex = 1;
    gap = 4;
    w = 0;
    for (i = startIndex; i < index; i++){
    L = thisComp.layer(i);
    w += L.width*L.transform.scale[0]/100 + gap;
    }
    w + width*scale[0]/200

    Dan

  • Eric Sanderson

    October 2, 2012 at 12:44 am

    So i told myself wouldnt come back on here for this, but after losing almost a whole workday trying figure it, or work arounds out on my own, ive hit a wall. Each one of these boxes this is for contains text in the bottom left corner, so the text obviously needs to move with the boxes, anchored at the bottom left where it is. Parenting is out because of the boxes scaling, and (value+) pick whipping to the boxes layer.anchor almost does it but the boxes anchor point is in the center. Moving the anchor to the left edge of the box seems to throw everything off. I even resorted to parenting and trying to counter the boxes scale with a linear negative scale on the text, lol, not a very precise result. Guess i just need to figure out a way to get the boxes anchor on the left, which is confusing because with the code it does seem to be physically anchored on the left (so then my moving the actual anchor point looks like the code runs another width/2 to the left of the shape) by the way it scales, i just need the coordinates to be that way too so i can reference it. Hope that is making sense and is an easy tweak, i poked and prodded at the code all day with no luck. Swear its the last one lol.

  • Dan Ebberts

    October 2, 2012 at 2:51 am

    This should position a layer on the left edge of another layer:

    L = thisComp.layer(“other layer”);
    x = L.transform.position[0] – L.width*L.scale[0]/200;
    [x,value[1]]

    This should do the same thing:

    L = thisComp.layer(“other layer”);
    x =L.toComp([0,0])[0];
    [x,value[1]]

    Do either of those help?

    Dan

    Dan

  • Eric Sanderson

    October 2, 2012 at 3:57 pm

    relief. Yes the second one is working. I’d imagine i could find in AE Help how that toComp and coordinates are working? Have a feeling this wont be the last time i could use that.

Page 1 of 2

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