ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Get all nested comps from a selected comp ?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Shai Benshoshan
Get all nested comps from a selected comp ?
on Mar 13, 2018 at 9:11:44 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


Return to posts index

Dan Ebberts
Re: Get all nested comps from a selected comp ?
on Mar 13, 2018 at 9:37:42 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



Return to posts index

Shai Benshoshan
Re: Get all nested comps from a selected comp ?
on Mar 14, 2018 at 9:50:29 am

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


Return to posts index


Shai Benshoshan
Re: Get all nested comps from a selected comp ?
on Mar 14, 2018 at 12:21:49 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);
}
}
}


Return to posts index

Dan Ebberts
Re: Get all nested comps from a selected comp ?
on Mar 14, 2018 at 4:09:15 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



Return to posts index

Shai Benshoshan
Re: Get all nested comps from a selected comp ?
on Mar 14, 2018 at 10:31:57 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]