Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Find the Master Composition from a precomp ( Extendscript )

  • Find the Master Composition from a precomp ( Extendscript )

    Posted by James Ronan on July 5, 2017 at 10:21 pm

    Hey guys

    I’ve written a function that will loop through all layers of an active comp, find any precomps, and loop through all those layers inside until there are none left.

    This is great if the active comp is the ‘Master Composition’. but if the function is executed inside a precomp it will only loop through the precomps within it.

    My question is: Is there a way that you can find what the master composition is from inside a precomp by looping upwards / backwards? Or another way?

    precompSearchFunction(app.project.activeItem);

    function precompSearchFunction(a){

    for(var i = 1; i <= a.layers.length; i++){ // Loops through all the layers active composition.
    if(a.layer(i).source instanceof CompItem){ // If layer source is an instance of a comp Item (precomp)
    //more code here
    precompSearchFunction(a.layer(i).source); // same function to search within precomps with in it.
    } else { // If it's not a comp item.
    return;
    }

    }// End of Function

    };

    Any help much appreciated!

    Thanks

    Dan Ebberts replied 8 years, 7 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    July 5, 2017 at 10:32 pm

    Check out the “usedIn” attribute. It returns an array of comps that use the item.

    Dan

  • James Ronan

    July 6, 2017 at 3:27 pm

    Amazing!

    That was just what I was looking for. Thanks, Dan!

  • James Ronan

    October 2, 2017 at 2:33 pm

    Hey Dan,

    Thanks again for your previous help, alas I’ve another question relating to the usedIn attribute …

    Using the attribute creates an array of what compositions an object is used in, but can it show you what the layer index is, of that item in that composition?

    E.g. if I right click on an item in the Project panel, and click “Reveal in Composition”, it will show me the composition, the layer index, and the name of the layer.

    Specifically, I’m looking for its index in that composition. So is the usedIn attribute still the way to go, or is there something else that could work?

    Thanks!

    James

  • Dan Ebberts

    October 2, 2017 at 10:52 pm

    I can’t think of anything better than looping through the usedIn comp layers, looking for AVLayers with a CompItem source where the id attribute of the source comp matches the id of comp you’re searching for.

    Dan

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