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 ?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With