【发布时间】:2019-08-13 14:13:55
【问题描述】:
我正在为 Premiere pro 编写一个脚本,我可以在时间轴中添加标记并一次性导出每个标记的静止图像。但是,当我编写一个函数来检查之前是否已经创建了静止图像时,这些函数告诉我它找到了以前创建的静止图像,但仍然创建了一个新的静止图像。 所以基本上:函数返回 true,但仍然执行 else{}
//checks if the frame that is about to be exported already exists
if(checkIfExist(app.project.rootItem, outputFile)){
alert("frame already exists");
}else{
//This is where the actual still gets created and imported
activeSequence.exportFramePNG(time, outputFileName);
//here the previously created item gets moved to the appropriate bin (This is working great ATM)
moveToBin(outputFile);
}
}
}
//This function is meant to check if an item exists in the project bin. It does this by looping though all the items in the array from the start.
function checkIfExist(currentItem, name){
for(var i = 0; i<currentItem.children.numItems; i++){
currentChild = currentItem.children[i];
if(currentChild.name.toUpperCase() === name.toUpperCase()){
alert("Found: " + currentChild.name);
return true;
}if(currentChild.type == ProjectItemType.BIN){
checkIfExist(currentChild, name);
}
}
return false;
}
【问题讨论】:
-
checkIfExist 运行的次数很可能超过了您认为它运行的次数。这是真的,但随后再次运行它是错误的,然后你的 else 也运行了
-
感谢您的回复。我如何检查是否可以?如果是这样,我该如何解决?
-
您可以通过在函数内部放置一个 console.log 来检查它是否记录了不止一次。也许还可以在函数中添加一个 if 语句。下面我的答案中可能的解决方案
标签: javascript extendscript adobe-premiere