我正在研究Adobe After Effects的Extendscript工具,并试图弄清楚一件事。 Extendscript只是Javascript的顶部添加了一些Adobe绒毛,但几乎任何Javascript都不是特定于浏览器的作品。图像序列的Javascript数组 - 仅返回序列中的第一个图像
我有一段脚本我一直在使用/开发一段时间,这大大简化了在图像序列中导入数千幅图像的过程。一切工作都很好,但有一个特定区域运行速度非常缓慢,当你开始进入数千张图像时,我正试图弄清楚如何加快速度。
我想要优化的是经过一系列可能有数千个图像文件,并将其连接到序列中的第一个图像。例如,我的数组可能是:[img.001.png,img.002.png,img.003.png,img.004.png,img.005.png],我想要做的是将每个“ img。###。png“除了第一个。所以在我的功能后,我只会:[img.001.png]。
以下是我现在就做:
1)我拿阵列项目A,正则表达式出来的数字序列
2)然后阵列B项,正则表达式出来的数字序列
3),并比较两个以看看它们是否相同。如果他们是我拼接项目B
这适用于100%的时间真棒,但是当你获得一千或两个图像以上时相当慢...我想要做的是找到一种方法更快地做到“修剪”步骤。我的一个朋友告诉我,正则表达式非常慢,所以也许我需要没有正则表达式呢?我还发现了几种原生JavaScript数组方法,它们可能有助于forEach()every()和filter(),但我不明白这些会如何更快,因为我仍然需要做2次正则表达式评估,而且我仍然需要比较项目彼此。
任何帮助将非常感激!
- 斯宾塞
这里是我现有的代码片段:
currentFolder = new Folder ("//12.34.5.67/my folder on the network/")
var folderChildren = currentFolder.getFiles().sort();
var searcher = new RegExp("\\d{3,5}[.]");
for (var i = 0; i < folderChildren.length; i++) {
// Go through the array and strip out all elements that are the same once their numbers have been removed with a regex
if (i > 0) {
currentResult = searcher.exec(folderChildren[i].name); //check if a sequence
if (currentResult) { // it is a sequence
// first parse out the comparison strings - current item and item before
var testNameBefore = folderChildren[i-1].name;
//if we have a sequence before our current item, we need to delete the numbers.
var beforeNum = searcher.exec(testNameBefore);
if (beforeNum) {
testNameBefore = testNameBefore.substring(0, testNameBefore.length-8);
}
var testNameCurrent = folderChildren[i].name;
testNameCurrent = folderChildren[i].name.substring(0, testNameCurrent.length-8);
//compare to the element before it and delete if the same!!
if (testNameBefore == testNameCurrent) {
folderChildren.splice(i, 1);
i--;
}
}
}
}
是文件格式始终* .Number.png? – Jecoms
它总是以Number.png结尾,但并不总是在数字之前的一段时间。数字序列并不总是3位数字。 – Spencer