如何通过脚本显示和隐藏标准的InDesign面板?

问题描述 投票:1回答:1

例如,我可以引用“脚本”面板;但似乎没有showhide方法,例如通过脚本创建的面板(请参见下面的代码)。如何在不调用相应菜单项的情况下以编程方式显示或隐藏它?

function findPanelByName(name) { // String → Panel|null
    for (var iPanel = 0; iPanel < app.panels.length; iPanel++) {
        var panel = app.panels[iPanel];
        if (panel.name == name) {
            return panel;
        }
    }
    return null;
}

var scriptsPanel = findPanelByName('Scripts');

scriptsPanel.show(); // → “scriptsPanel.show is not a function”
adobe-indesign extendscript
1个回答
2
投票

几件事:获得正确面板的方法不必要地复杂。您可以像这样使用面板集合的item方法来获取面板:

var scriptsPanel = app.panels.item('Scripts');

然后,您不需要使用show()来显示面板(因为该方法不存在),而是可以通过将其visible属性设置为true来显示面板:

scriptsPanel.visible = true;

最后,如果要让其他人使用该脚本,则应确保该脚本也可以与InDesign的国际版本一起使用。例如,在我的德语版本中,上面的面板将不存在,因为它名为Skripte而不是Scripts。为了避免这种情况,您可以使用InDesign的语言独立键:

var scriptsPanel = app.panels.item('$ID/Scripting');

因此,总的来说,整个脚本可以缩短到这种单行代码

app.panels.item('$ID/Scripting').visible = true;
© www.soinside.com 2019 - 2024. All rights reserved.