循环完成速度比文件对象快 read/write/import

Loop is finishing faster than file object read/write/import

我以前从未遇到过 extendscript 的这个问题,我认为 extendscript 是同步的。我在数组中循环:对于数组中的每个对象,我打开、读取和更新 xml,然后将其导入 PPro。我认为循环比文件更新和导入更快地完成 - 没有文件被导入。

如果我 alert(array[i]) 每次一切正常,但一旦我注释掉警报,文件将不再导入。

function importXML(targetFile){
    app.project.importFiles([targetFile], 1); // 1 == suppress UI
    updateEventPanel('Media imported for ' + show);
    return 'success';
}


function processXML(obj){
    var shows = obj.shows;
    // alert(shows.length);

    var currentShow = obj.shows[0];

    for(var i = 0; i < shows.length-1; i++){
        var xmlDoc = obj.targetXml;
        var show = obj.shows[i+1];
        // alert('currentShow: ' + currentShow);
        // alert('show: ' + show);

        var currentValue1 = new RegExp('<Name>'+ currentShow, 'g');
        var currentValue2 = new RegExp('HIGHLIGHT_VERSIONING/'+ currentShow, 'g');
        var newValue1 = '<Name>'+ show;
        var newValue2 = 'HIGHLIGHT_VERSIONING/'+ show;

        var myFile = new File(xmlDoc);
            myFile.open('e', undefined, undefined);

        var inText = myFile.read();
            inText = inText
                .replace(currentValue1, newValue1)
                .replace(currentValue2, newValue2);

        myFile.seek(0);
        myFile.write(inText);
        myFile.close();

        updateEventPanel('XML updated for ' + show);

        importXML(xmlDoc);
        // updateEventPanel('Media imported for ' + show);

        currentShow = show;
    };
}

在从静态 csv 文件读取数据之前,我 运行 遇到过类似的问题...我有一个用于 scriptUI 下拉菜单的 onChange 事件,但它们只会像定时一样填充一半- 读到一半就出去了。我去寻找一个类似 settimeout 的函数,我发现 ESTK 有一个用于添加延迟的 $.sleep() 方法:

sleep()
$.sleep(milliseconds)

milliseconds    
The number of milliseconds to wait.
Suspends the calling thread for the given number of milliseconds.

During a sleep period, checks at 100 millisecond intervals to see 
whether the sleep should be terminated. This can happen if there is 
a break request, or if the script timeout has expired.

Returns: undefined

您可以在 aenhancers estk 文档中阅读有关美元对象的所有信息:https://estk.aenhancers.com/8%20-%20ExtendScript%20Tools%20and%20Features/dollar-object.html