ExtendScript 从搜索的 Comp 结果中获取索引号

ExtendScript get index number from searched Comp result

我有这段代码可以对 After Effects 中的各种项目进行排序,并 returning 项目中的所有合成,然后我根据我正在寻找的特定合成缩小范围,在本例中以 assemble 结尾。我得到了名字,这很好,但我真正需要的是索引号和名字,所以当我搜索 assemble 时,我得到 return of app.project.item(3 ), 它在项目中的索引 window。每次我尝试从数组中获取数字时,我似乎得到的只是没有帮助的项目总数。

谢谢。

function retrieveProjectItems(itemType){
var typeOptions = ["Composition", "Folder", "Footage"];
for(var t = 0; t<3; t++){
    if(itemType == typeOptions[t]){
        var proj, itemTotal, curItem, itemArray;
        itemAry = [];
        proj = app.project;
        itemTotal = proj.numItems;
        for(var i = 1; i <= itemTotal; i++){
            curItem = proj.item(i);

            //alert(curItem.name);


            if(curItem.typeName == itemType){
                itemAry[itemAry.length] = curItem.name;
                }
            }
        return itemAry;

        }
    }
}
retrieveProjectItems("Composition");
//alert(comps); lists all COMPS in the Array

var comps = itemAry;
var compWithAssemble;
for(var i in comps){
if(comps[i].indexOf("assemble") > -1){ ///search for part of the name///////////////////////////////////
    compWithAssemble = comps[i];

    break;
}
}
// compWithAssemble has the string you are looking for.
alert(compWithAssemble);
//app.project.item(3).selected = true;
compWithAssemble.selected = true; //I'm looking to make this work...

我假设您想以编程方式找到包含名为 "assemble"

的图层的合成

这段代码

if(comps[i].indexOf("assemble") > -1){ ///search for part of the name///////////////////////////////////
    compWithAssemble = comps[i];

    break;
}

不会给您想要的结果,因为 comps[i] 是 CompItem 的对象,而不是数组或集合。您需要先检索每个 comp[i] 的图层集合。然后,当您拥有该 LayerCollection 时,您可以使用 .byName() 方法找到名为 "assemble" 的图层。如果您没有获得返回的图层,您将收到 null,否则,您将收到一个图层对象。

它可能看起来像:

var comps = itemAry;
var compWithAssemble;

for (var i in comps){
    if(comps[i].layers.byName("assemble") != null) {
       compWithAssemble = comps[i];
       break;
    }
}