Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Looking for a better way for write this.

  • Looking for a better way for write this.

    Posted by Eric Sanderson on July 9, 2010 at 3:56 pm

    So i have these rectangles i want to make up the days of a Calendar with. I have a top “Controller” null layer with some x and y offset sliders for the gap between the rectangles and using the index-1 method to distribute them. But obviously a calendar isnt a straight horizontal row of days. I remember seeing a grid code by Dan a while back that may work, but thats a little more complex for me at the moment. I wrote this code that actually does exactly what i want it to, but i think it may be kind of a crude way of accomplishing it and im sure theres a better cleaner way out there. For instance i was trying to figure out how to make every 7th layer move down on the Y without having to create a separate variable for each row, played around with “++*7” on my one variable but wasnt doing it. But if anyone can take my code and clean it up, introduce some new methods to me i think it would be a good learning process, thanks a lot :).

    i1 = thisComp.layer("calendar shape").index+7;
    i2 = thisComp.layer("calendar shape").index+14;
    i3 = thisComp.layer("calendar shape").index+21;

    Ci = thisLayer.index;

    x1 = thisComp.layer(index-1).transform.position[0]+thisComp.layer("controller").effect("xOffset")("Slider");
    x2 = thisComp.layer("calendar shape").transform.position[0];

    y1=thisComp.layer(index-1).transform.position[1];
    y2=thisComp.layer(index-1).transform.position[1]+thisComp.layer("controller").effect("yOffset ")("Slider");

    z=thisComp.layer(index-1).transform.position[2];

    r1 = [x1,y1,z];
    r2 = [x2,y2,z];

    if(Ci==i1||Ci==i2||Ci==i3){r2
    }else{
    r1
    }

    Dan Ebberts replied 15 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    July 9, 2010 at 6:48 pm

    Something like this should work:

    xOffset = thisComp.layer(“controller”).effect(“xOffset”)(“Slider”);
    yOffset = thisComp.layer(“controller”).effect(“yOffset “)(“Slider”);

    numCols = 7;
    origin =thisComp.layer(“calendar shape”).transform.position;
    myIdx = index-thisComp.layer(“calendar shape”).index;
    myCol = myIdx%numCols;
    myRow = Math.floor(myIdx/numCols);
    origin + [(width + xOffset)*myCol, (height + yOffset)*myRow]

    Dan

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