Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Extendscript for AE. Reference comp by NAME, not by index.

Explorer ,
Dec 16, 2017 Dec 16, 2017

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.

TOPICS
Scripting
5.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Dec 17, 2017 Dec 17, 2017

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;

      

...
Translate
Advocate ,
Dec 16, 2017 Dec 16, 2017
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 17, 2017 Dec 17, 2017

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 17, 2017 Dec 17, 2017
LATEST

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 17, 2017 Dec 17, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines