Copy link to clipboard
Copied
Hi everyone, first time poster.
I'm making my own plugins for AE for my own toolkits.
I have a main composition called MAIN_CONTROL. What i want to do is reference this by the name and not index. I want to see if this comp contains a layer, and run a function based on whether or not it does. So....
var chkLayer = app.project.MAIN_CONTROL.layer("Layer Name");
if (chkLayer == undefined){
//do this
}else{
//do that
}
As of now i can access it by "index" using app.project.item(1).layer("Layer Name")......
But as i build my project and if i re-organize that MAIN CONTROL comp into a subfolder, the index changes and everything breaks.
For some reason this seems so basic, but it is a pain in the butt.
Any help is appreciated.
So if you looped through the project items, and found your matching comp. You can use either the index value, or the object itself. Both will work, but the object way is cleaner.
var proj = app.project;
var itms = proj.items;
var itmsLen = itms.length;
var curItem, myComp;
for(var i=0; i<itmsLen; i++){
curItem = itms;
If(curItem instanceof CompItem){
If(curItem.name == “your comp name”){ //Will grab only the first name match
myComp = curItem;
break;
...
Copy link to clipboard
Copied
I did an entire episode on this exact task.
https://www.provideocoalition.com/free-function-friday-findcompbyname/
Copy link to clipboard
Copied
Thank you. I watched this is i believe i get the underlying logic.
Search for a comp to match a string name by narrowing the search from all items,to comp items, case sensitive.
Where i get hung up is taking that final result and plugging that into another function as a variable.
So if i get the proper comp based on my search, and i want to use it in my chkLayer from up above how would that plug in?
Copy link to clipboard
Copied
So if you looped through the project items, and found your matching comp. You can use either the index value, or the object itself. Both will work, but the object way is cleaner.
var proj = app.project;
var itms = proj.items;
var itmsLen = itms.length;
var curItem, myComp;
for(var i=0; i<itmsLen; i++){
curItem = itms;
If(curItem instanceof CompItem){
If(curItem.name == “your comp name”){ //Will grab only the first name match
myComp = curItem;
break;
}
}
}
var chkLayer = myComp.layer("Layer Name");
if (chkLayer == undefined){
//do this
}else{
//do that
}
Copy link to clipboard
Copied
Unfortunately, there is no way to reference the composition by its name.
You can only assign your composition to the variable and then reuse it.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now