6

I am working on After Effects scripts and using AE scripting guide as a base of learning.

I have one After Effect project which includes two AE projects in it and each of the project having multiple items in it.

I want to fetch the composition from the master project having specific name but without looping through all items in the project. For example,

var myComp = app.project.comp("Composition Name");

Is this possible ? Is there any other way around ?

m.s.
  • 16,063
  • 7
  • 53
  • 88
Pooja
  • 61
  • 1
  • 4

1 Answers1

8

You can get the comp in this way:

var myComp;
for (var i = 1; i <= app.project.numItems; i ++) {
    if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === 'Comp Name')) {
        myComp = app.project.item(i);
        break;
    }
}

Be aware that if you want to check if there's no more comp with the same name you should write it like this:

var myComp;
for (var i = 1; i <= app.project.numItems; i ++) {
    if ((app.project.item(i) instanceof CompItem) && (app.project.item(i).name === 'Comp Name')) {
        if (myComp) {
            throw new Error();//or something else
        }
        myComp = app.project.item(i);
    }
}

And if you want you can put it in array and check if it's the only return myComp[0] and if not do womething like throw error

Ziki
  • 1,390
  • 1
  • 13
  • 34