Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to make PreComps reposition within confines of a Master Comp?

  • Expression to make PreComps reposition within confines of a Master Comp?

    Posted by David Byrne on March 21, 2013 at 12:48 pm

    Hello folks!

    I’ve been trying to set up a sort of contact sheet full of various precomps, all of which will be the same size – and rather than creating a huge comp that ends up being 30,000 x wide, I decided to bring all my Precomps in and have them scaled down, allowing me to move the camera around this comp, still being able to close in and use continual rasterisation for quality. (This is possibly redundant info but I thought it might help).

    I have decided to use an expression to make the comps line up one after another within the confines of this Master Comp.

    I have also used a Slider Control which controls the scale of all comps. The way I did this was to add a “value/” expression and link to the Slider Control.

    Currently for test purposes this slider is set to 5, which means I can fit 5 precomps across the comp’s width and of course, 5 in height, totalling 25 comps.

    What I want however is to be able to adapt this quickly if necessary to maybe 6×6 or 10×0 and the comps to realign themselves within this Master Comp.

    Oh and all comps within this Master Comp have had their anchor points set to 0,0. The first Precomp has no expression and is simply positioned at 0,0 as well so top left in the comp. Fans of the X-Files will appreciate my naming shortcuts.
    So here’s my expression so far (remember the Slider controller is set to 5):

    Mulder=thisComp.layer(“Scale of Comps Controller”).effect(“Scale Slider”)(“Slider”); // This as I say scales the precomps, currently set to 5
    Scully=thisComp.height/thisComp.layer(“Scale of Comps Controller”).effect(“Scale Slider”)(“Slider”); // This used to make the second row.
    Skinner=thisComp.layer(index-1).transform.position[0]+thisComp.width/Mulder; // This used to make each following comp move horizontally 1 precomps width to the right.
    Krycek=thisComp.layer(index-1).transform.position[1]; // And finally the Height shortcut, simply pointing to the above layers height to find it’s value.

    [Skinner,Krycek]; // so up to here I have the comps moving out across the comp, by 1 precomp width each time. However they do not constrain to the Master Comp size. So I used this if/else expression.

    if
    (Skinner > thisComp.width-1){
    [0,1+Scully];

    }else{[Skinner,Krycek];};

    // Simply put, if the X position of the precomp is greater than the width of the Master Comp (minus 1 as otherwise it will position a precomp at 1920), reset the xPosition to 0 and adjust the Yposition to The Height of the Comp / Scale value (in this case 5)

    Here is the expression without my annotations:

    Mulder=thisComp.layer(“Scale of Comps Controller”).effect(“Scale Slider”)(“Slider”);
    Scully=thisComp.height/thisComp.layer(“Scale of Comps Controller”).effect(“Scale Slider”)(“Slider”);
    Skinner=thisComp.layer(index-1).transform.position[0]+thisComp.width/Mulder;
    Krycek=thisComp.layer(index-1).transform.position[1];

    [Skinner,Krycek];

    if
    (Skinner > thisComp.width-1){
    [0,1+Scully];

    }else{[Skinner,Krycek];};

    So far this expression gives me a comp that allows ten precomps along two rows to reposition accordingly. However the 11th precomp resets to the start of the second row, as I haven’t been able to give it a new yPosition value.

    I thought of finding an expression to add to the “if / else” that told it to see if any other layers held the same position, and if so, to move down by the height division + the previous layers height (in my shortcut speak, Scully + the Y Position of Index-1).

    This I think would solve the problem as, given the first calculation (dictating width), the only time a comp could possibly be in the same position as another would be if it had reached the end of it’s row, and via the width position constraint had gone back to square one.

    Therefore making it jump down one row in this circumstance, I could ensure its following Precomps would look to their predecessors for their relative Height (using the Krycek shortcut).

    I am however now at my limits of expressions and lost.

    I’m also wondering if I am missing a bloody obvious trick here by trying to be too clever by half!

    Any thoughts or suggestions would be hugely appreciated folks.

    Thanks in advance!

    Dave Byrne
    Animo Motion Graphics.

    David Byrne replied 13 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 21, 2013 at 1:52 pm

    Assuming that your comp layers are at the top of the layer stack and that the anchor points are set to [0,0], something like this should work for position:

    nCols = 5;
    myRow = Math.floor((index-1)/nCols);
    myCol = (index-1)%nCols;
    [myCol*thisComp.width,myRow*thisComp.height]/nCols

    Dan

  • David Byrne

    March 21, 2013 at 2:00 pm

    Hey Dan, thanks for your fast feedback mate.

    I actually just came on to post my solution and saw your response so will try shortly! Sure it’s better than my convoluted version, but effectively here was my solution:

    Mulder=thisComp.layer(“Scale of Comps Controller”).effect(“Scale Slider”)(“Slider”);
    Scully=thisComp.height/Mulder;
    Skinner=thisComp.layer(index-1).transform.position[0]+thisComp.width/Mulder;
    Krycek=thisComp.layer(index-1).transform.position[1]+Scully*0;

    [Skinner,Krycek];

    if
    (Skinner > thisComp.width-1){
    [0,Scully+thisComp.layer(index-1).transform.position[1]];

    }else{[Skinner,Krycek];};

    The change was to say that when it hits the end of the row (ie the Precomp position exceeds the width of the comp), as well as adjusting the xPos back to 0, the yPos should not only take the Scully measurement (ie the Height of the Comp divided by the Slider Control scaler) but also add on the previous layer’s yPosition. Relatively simple, for some reason didn’t think of it until after posting, guess getting it all down on paper and talking it over with a colleague helped my creative juices!

    As the only time that the position shifts to the next row is when it hits the width of the Master Comp, we can safely assume that the previous layer’s Height will always be the parameter to add to the Scully measurement.

    I’ve played around with it briefly and with over 100-odd comps it all rearranges perfectly to within the confines of my Master Comp. (If I reduce the scaler to say 5 again, I have a lot of unwanted Precomps out of sight of my Master Comp but hey, thats the point, they can be added or deleted as needed by the size of the precomps, until they fill the Master Comp.

    The only thing now to do is make each a different precomp!

    Thanks again Dan will try out your expression as well, good to learn some new techniques!

    Cheers!
    Dave Byrne
    Animo Motion Graphics

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