Activity › Forums › Adobe After Effects Expressions › How to list all layers and sub comp inside a selected comp in timeline
-
How to list all layers and sub comp inside a selected comp in timeline
Posted by Clara Martin on May 27, 2024 at 8:50 pmHello,
I have a pre composition in my timeline named “A”
– In “A” there are 2 text layers “T1” and “T2” and another composition named “B”
– In “B” there are 2 text layers “T3” and “T4” and another composition named “C”
– In C there is 1 text layer “T5”
How to do it when I select the pre comp “A” in the timeline I get the complete list of all the elements in A:
– T1
– T2
-B
– T3
– T4
– VS
– T5
Thanks in advance 🙂
Brie Clayton replied 2 years, 1 month ago 3 Members · 8 Replies -
8 Replies
-
Dan Ebberts
May 27, 2024 at 9:13 pmWhat do you mean by “list”? And are you talking about an expression or a script?
-
Clara Martin
May 28, 2024 at 6:00 amSo it’s for a script.
I would like to know if it is possible to know all the children (layers and precomp in the parent precomp etc. as in my example) of a precomp by selecting it in my timeline.
I want to loop over it (for loop).
There can be several levels as in my example:
– A parent precomp who has a child who himself has a child etc.
Do you think this is possible?
Thanks in advance 🙂
-
Dan Ebberts
May 28, 2024 at 6:29 amCertainly possible, but one question is what you want to do with the information. If you’re talking about a script, I guess it could write it to a text file. Is that what you’re picturing?
-
Clara Martin
May 28, 2024 at 6:44 amHello,
Yes I have a .jsx file that I use to do what I want.
For your first question, I have a csv file which contains data, by looping over the child layers and precomp I want to impose certain data on them from the csv file (this part works)
I’m just having trouble getting the part of finding all the children of a precomp selected from my timeline to work.
Thank you 🙂
-
Dan Ebberts
May 28, 2024 at 2:43 pmI’m still not clear on exactly how you want the names formatted, but this simple script will pop up an alert that lists all the layer names (and those of any sub comps) in the selected comp:
function test(){
var names = [];
function getNames(theComp){
for (var i = 1; i <= theComp.numLayers; i++){
names.push(theComp.layer(i).name);
if (theComp.layer(i).source instanceof CompItem){
getNames(theComp.layer(i).source);
}
}
}
var comp = app.project.activeItem;
if (! comp || ! (comp instanceof CompItem)){
alert("No comp active.");
return;
}
getNames(comp);
alert(names.join("\r"));
}
test() -
Dan Ebberts
May 28, 2024 at 4:49 pmHere’s another version that puts indents for each level of nested comps:
function test(){
var names = [];
function getNames(theComp, thePrefix){
for (var i = 1; i <= theComp.numLayers; i++){
names.push(thePrefix + theComp.layer(i).name);
if (theComp.layer(i).source instanceof CompItem){
getNames(theComp.layer(i).source, thePrefix+" ");
}
}
}
var comp = app.project.activeItem;
if (! comp || ! (comp instanceof CompItem)){
alert("No comp active.");
return;
}
getNames(comp,"");
alert(names.join("\r"));
}
test(); -
Clara Martin
May 30, 2024 at 10:51 amHello thank you very much,
the last script with the test() function does exactly what I wanted.
Thank you very much
Reply to this Discussion! Login or Sign Up