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 pmI 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 ;
ShaiShai Benshoshan replied 8 years, 2 months ago 2 Members · 5 Replies -
5 Replies
-
Dan Ebberts
March 13, 2018 at 9:37 pmSomething 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 amWorking like magic!
A function that runs on itself
Thanks, Dan ! -
Shai Benshoshan
March 14, 2018 at 12:21 pmI 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<=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 <= 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 pmTry 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 pmMany 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
Reply to this Discussion! Login or Sign Up