循环比文件对象读/写/导入快

时间:2019-08-01 18:58:14

标签: extendscript adobe-premiere

我以前从未遇到过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;
    };
}

1 个答案:

答案 0 :(得分:1)

在从静态csv文件读取数据之前,我遇到了类似的问题...我有一个onChange事件,用于scriptUI下拉菜单,但填充时只有一半,就像读取一半时超时一样。我去寻找一个类似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

您可以在增强的estk文档:https://estk.aenhancers.com/8%20-%20ExtendScript%20Tools%20and%20Features/dollar-object.html

中阅读有关美元对象的所有信息。