Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to Change a Precomp's Setting with ExtendScript

  • How to Change a Precomp's Setting with ExtendScript

    Posted by Linden Stirk on December 3, 2020 at 5:41 am

    Is there a way to change a precomp’s setting and the layers inside it while inside the master comp? It seems accessing the precomp’s height for example is “read-only”. How can I “enter” the precomp, change the settings, and then go back to the main comp? Any suggestions would be most appreciated.

    // convert each layer into a precomp

    var parentComp = app.project.activeItem;

    var selected = parentComp.selectedLayers;

    for (var i = 0; i < selected.length; i++) {

    processLayer(parentComp, selected[i]);

    }

    function processLayer(parentComp, layer) {

    var layerIndex = layer.index;

    var layerIndices = new Array(1);

    layerIndices[0] = layerIndex;

    parentComp.layers.precompose(layerIndices, layer.name, true); // (moveAllAttributes = true);


    // *this is the part that doesn’t work because properties of “precomp” are read-only

    var precomp = parentComp.layer(layerIndex);

    adjustComp(precomp);} function adjustComp(comp) {

    // adjust height, width, and trim to layer(1)’s outPoint

    }

    A possible alternative solution would be to create a comp, add the layer that needs to be in the comp, then delete the original layer, but I’d like to know if it’s possible just to change the precomp’s settings directly. More info in case what I’m doing doesn’t make sense: I have a comp with hundreds of video files that have been synced to audio in Premiere. It’s a virtual choir with different singers coming in at different times. Each layer needs to be processed and rendered out as an individual image sequence, and the start time of each layer needs to be preserved. The first n number of frames of some singers will be black before the singer starts, which is fine.

    Update: I solved it. See below.

    Linden Stirk replied 5 years, 6 months ago 1 Member · 1 Reply
  • 1 Reply
  • Linden Stirk

    December 3, 2020 at 5:46 am

    Oops, well I’m idiot… For anyone else who stumbles upon this, here is what I did:

    function adjustComp(newComp) {

    // find the comp in the project window

    for (var j = 1; i <= app.project.numItems; j++) {

    var selectedComp;

    if ((app.project.item(j) instanceof CompItem) && (app.project.item(j).name === newComp.name)) {

    selectedComp = app.project.item(j);

    break;

    }

    }
    }

    // then do stuff with selectedComp

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