Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get composition by its name in after effects project using extend script

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 ?

like image 673
Pooja Avatar asked Oct 15 '15 10:10

Pooja


1 Answers

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

like image 198
Ziki Avatar answered Oct 12 '22 06:10

Ziki