Skip to main content
varxtis
Inspiring
January 21, 2019
Answered

Can one put a group of layers into independant precomps?

  • January 21, 2019
  • 2 replies
  • 10966 views

I have a crap-load of layers that each need to be in their own precomp. Is there any way, script or plug-in, that would allow me to select a group of layers from the time line and make it so each of those layers get into their own precomp?

    Correct answer Dave Merchant

    Im sorry it took so long to respond. I finally had a chance to try this, but I get the error

    "Unable to execute script at line 8. undefined is not an object"

    Line 8 is:

    if (thislayer.selected) selectedLayers.push(i);

    I have the comp selected. I have nothing but the shape layers im wanting to pre-compose in the comp, and I have them all highlighted/selected before running the script.

    Since it's a script and not an expression, I don't think I have to define an index number/range, so im at a bit of a loss on whats goin' on here.


    Sorry, missed a line when I pasted:

    var moveAllAttributes = true;
    var laycol = app.project.activeItem.layers;


    // first cache the array of layer selections, starting at the bottom
    var selectedLayers = new Array();
    for (var i=laycol.length; i>0; i--) {

        var thislayer = laycol;
        if (thislayer.selected) selectedLayers.push(i);
    }


    // now precompose them individually
    for (var s=0; s<selectedLayers.length; s++) {
        var thislayer = laycol[selectedLayers];
        var precomp_name = thislayer.name;
        laycol.precompose([selectedLayers],precomp_name,moveAllAttributes);
    }

    2 replies

    JCIOM
    Participant
    April 3, 2025

    i know its a long time since this question but i created a plugin that can do this> precomps each layer to their own precomp.. while trimming it to the duration of each layer,, its free,, check it out...

    jciomkenya precomposehelper 

    Community Expert
    January 21, 2019

    You can group by color labels and then pre-compose.

    Pre-composing this one simple keystroke. I know of no way to write a script that automatically selects Different groups of layers unless you have already group layers by color, but, on the other hand, if layers are out of order or you can’t precomposed them anyway.

    Maybe I do not understand what you’re trying to do but shift select and the keyboard shortcut seems like a lot less trouble than digging for a script and then running It.

    varxtis
    varxtisAuthor
    Inspiring
    January 21, 2019

    First off, thank your for your time and your response.

    So, lets say you have a comp with 20 shape layers in your timeline. Thats all, just 20 shape layers. You can select all 20, and put them into one precomp. Or, you can go one by one and put each of them in their own precomp.

    I have a lot more than 20 and I need each of them to be in their own precomp. Going one by one seems very inefficient, and will take a long time. I figure there has got to be a way to select all 20 (going back to the example) and telling After Effects to put each one of the selected layers in its own precomp.

    Legend
    January 21, 2019

    It would be possible with a script, but it has to be done carefully.

    There is a layerCollection.precompose() function but it uses the index number of the layer(s) to be precomposed (the number shown next to the name in the timeline panel). Since every time you precompose a layer, the numbers will change, the script has to work from the bottom up. The act of precomposing also resets any selection, so if you're using that rather than something like label colors to choose your targets, the script has to cache their numbers.

    Here's a very basic script that does that. I assume you have the composition selected in the project panel, and the layer(s) selected in the timeline - and that the layers make sense to precompose in isolation:

    var moveAllAttributes = true;
    var laycol = app.project.activeItem.layers;


    // first cache the array of layer selections, starting at the bottom
    var selectedLayers = new Array();
    for (var i=laycol.length; i>0; i--) {
        if (thislayer.selected) selectedLayers.push(i);
    }


    // now precompose them individually
    for (var s=0; s<selectedLayers.length; s++) {
        var thislayer = laycol[selectedLayers];
        var precomp_name = thislayer.name;
        laycol.precompose([selectedLayers],precomp_name,moveAllAttributes);
    }