Javascript ExtendScript从搜索的Comp结果中获取索引号
我有一段代码,它对after effects中的各个项目进行排序,并返回项目中的所有组成部分,然后根据我正在寻找的特定组成部分缩小范围,在本例中,以Assembly结尾的组成部分。我得到了名称,这很好,但我真正需要的是名称附带的索引号,这样当我搜索Assembly时,我会返回app.project.item(3),它在项目窗口中的索引。每次我试图从数组中获取数字时,我似乎只得到了没有帮助的项目总数 谢谢Javascript ExtendScript从搜索的Comp结果中获取索引号,javascript,arrays,extendscript,Javascript,Arrays,Extendscript,我有一段代码,它对after effects中的各个项目进行排序,并返回项目中的所有组成部分,然后根据我正在寻找的特定组成部分缩小范围,在本例中,以Assembly结尾的组成部分。我得到了名称,这很好,但我真正需要的是名称附带的索引号,这样当我搜索Assembly时,我会返回app.project.item(3),它在项目窗口中的索引。每次我试图从数组中获取数字时,我似乎只得到了没有帮助的项目总数 谢谢 function retrieveProjectItems(itemType){ var t
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...
函数检索项目项(itemType){
var typeOptions=[“合成”、“文件夹”、“镜头”];
对于(var t=0;t,我假设您希望通过编程查找具有名为“assembly”
这段代码
if(comps[i].indexOf("assemble") > -1){ ///search for part of the name///////////////////////////////////
compWithAssemble = comps[i];
break;
}
不提供所需的结果,因为comps[i]
是CompItem的对象,而不是数组或集合。您需要首先检索每个comp[i]
的层集合。然后,当您拥有该层集合时,您可以使用.byName()找到名为“Assembly”
的层方法。如果您没有得到返回的层,您将收到null
,否则,您将收到一个层对象
它可能看起来像:
var comps = itemAry;
var compWithAssemble;
for (var i in comps){
if(comps[i].layers.byName("assemble") != null) {
compWithAssemble = comps[i];
break;
}
}