防止在InDesign CC JavaScript中显示进度条时出现对话框和警告

Prevent dialogs and alerts while showing a progress bar in InDesign CC JavaScript

本文关键字:对话框 警告 InDesign CC JavaScript 显示      更新时间:2023-09-26

我的脚本分析一堆InDesign文件。任何关于缺少字体等的警告都是无关紧要的,因此我在核心工作期间关闭了用户交互:

// preparation code
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
// core work code
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
// finish code

尽管如此,我还是想显示一个进度条。我用ScriptUI:

设置了这一点
progressPanel = new ProgressPanel(files.length, 500);
progressPanel.show();
for (i = 0; i < files.length; i++) {
    processFile( files[i] );
    progressPanel.incr();
    progressPanel.setText( files[i].name );
    progressPanel.show();
}
// Progress Panel, inspired from:
// http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/indesign/sdk/cs6/scripting/InDesign_ScriptingGuide_JS.pdf
// We make it a class.
function ProgressPanel (myMaximumValue, myProgressBarWidth){
    this.myProgressPanel = new Window('window', 'analyse InDesign files…');
    this.value = 0;
    this.myProgressPanel.myProgressBar
        = this.myProgressPanel.add('progressbar', 
                                 [12, 12, myProgressBarWidth, 24], 
                                    0, myMaximumValue);
    this.myProgressPanel.myText
        = this.myProgressPanel.add("statictext", 
                                   [15, 6, myProgressBarWidth, 24]);    
    this.show = function() {
        this.myProgressPanel.show();
    }
    this.hide = function() {
        this.myProgressPanel.hide();
    }
    this.setValue = function(value) {
        this.value = value;
        this.myProgressPanel.myProgressBar.value = value;
    }
    this.incr = function() {
        var inc = arguments.length ? arguments[0] : 1;
        this.value += inc;
        this.myProgressPanel.myProgressBar.value = this.value;
    }
    this.setText = function(text) {
        this.myProgressPanel.myText.text = text;
    }
}

这在InDesign cs6中工作得很好。但在CC 2015中不会,除非我删除所有NEVER_INTERACT语句。

在InDesign cs6和更新版本中,我如何在显示进度条的同时抑制其他用户交互?

至少在InDesign CC 2017中,调用win.update()可以做到!(参见进度条错误。Adobe论坛中关于ID CC中调色板窗口的更多信息的情况摘要。

this.show = function() {
    this.myProgressPanel.show();
    this.myProgressPanel.update();
}
this.incr = function() {
    var inc = arguments.length ? arguments[0] : 1;
    this.value += inc;
    this.myProgressPanel.myProgressBar.value = this.value;
    this.myProgressPanel.update();
}