Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Get all nested comps from a selected comp ?

  • Get all nested comps from a selected comp ?

    Posted by Shai Benshoshan on March 13, 2018 at 9:11 pm

    I need to ‘Drill down’ to a selected comp (activeItem) and any nested comp layer, to find all the text layer used;
    Trying to come up with the simplest way to loop through the layers and stop when there are no compositions layers.

    Thank you ;
    Shai

    Shai Benshoshan replied 8 years, 2 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    March 13, 2018 at 9:37 pm

    Something like this maybe:


    var myTextLayers = [];
    function processComp(theComp,theArray){
    for(var i = 1; i <= theComp.numLayers;i++){
    if (theComp.layer(i) instanceof TextLayer){
    theArray.push(theComp.layer(i));
    }else if (theComp.layer(i).source instanceof CompItem){
    processComp(theComp.layer(i).source,theArray);
    }
    }
    }
    var myComp = app.project.activeItem;
    processComp(myComp,myTextLayers);
    alert(myTextLayers.length);

    Dan

  • Shai Benshoshan

    March 14, 2018 at 9:50 am

    Working like magic!
    A function that runs on itself
    Thanks, Dan !

  • Shai Benshoshan

    March 14, 2018 at 12:21 pm

    I am now trying to get the fonts from all the text layers I found;
    Iterating through the layers Array isn’t working(” undefined” ), I think because it is a layer object;
    tried to push the layer name …. theArray.push(theComp.layer(i).name).toString()); which did return an array of layers name, but couldn’t get the font name of each layer ;

    Thank you for your help

    shai

    var activeItem = app.project.activeItem;
    var myComp;
    if ((activeItem !== null) && (activeItem instanceof CompItem))
    {myComp = app.project.activeItem} else {

    alert ("please select a comp");};

    var myTextLayers = [];
    processComp(myComp,myTextLayers);
    alert(myTextLayers);
    for (var k=0; k&lt;=myTextLayers.length;k++){}
    var mySourceText = myTextLayers[k];
    var mySourceText = TextLayer.property("ADBE Text Properties").property("ADBE Text Document");
    var myTextDoc = mySourceText.value;
    var fCurName = myTextDoc.font;
    alert(fCurName);

    function processComp(theComp,theArray){
    for(var i = 1; i &lt;= theComp.numLayers;i++){
    if (theComp.layer(i) instanceof TextLayer){
    theArray.push(theComp.layer(i));
    }else if (theComp.layer(i).source instanceof CompItem){
    processComp(theComp.layer(i).source,theArray);
    }
    }
    }

  • Dan Ebberts

    March 14, 2018 at 4:09 pm

    Try it this way:


    function processComp(theComp,theArray){
    for(var i = 1; i <= theComp.numLayers; i++){
    if (theComp.layer(i) instanceof TextLayer){
    theArray.push(theComp.layer(i));
    }else if (theComp.layer(i).source instanceof CompItem){
    processComp(theComp.layer(i).source,theArray);
    }
    }
    }
    function main(){
    var activeItem = app.project.activeItem;
    var myComp;
    if ((activeItem !== null) && (activeItem instanceof CompItem)){
    myComp = app.project.activeItem;
    } else {
    alert ("please select a comp");
    return;
    }
    var myTextLayers = [];
    processComp(myComp,myTextLayers);
    for (var k=0; k < myTextLayers.length;k++){
    var myTextLayer = myTextLayers[k];
    var mySourceText = myTextLayer.property("ADBE Text Properties").property("ADBE Text Document");
    var myTextDoc = mySourceText.value;
    var fCurName = myTextDoc.font;
    alert(fCurName);
    }
    }
    main();

    Dan

  • Shai Benshoshan

    March 14, 2018 at 10:31 pm

    Many Thanks!
    Now that I can collect the fonts to an array, in a composition with 300 font nested, most of them copies of one font),
    I need to sort the array so fonts that are already in the array will be excluded.
    Thanks again;

    Shai

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