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

1

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 ?

Kanchenjunga answered 15/10, 2015 at 10:23 Comment(0)
M
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

Muntjac answered 16/10, 2015 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.