InDesign ScriptUI窗口出现后立即消失

InDesign ScriptUI windows disappearing immediately after appearing

本文关键字:消失 ScriptUI 窗口 InDesign      更新时间:2023-09-26

我已经有一段时间没有遇到ExtendScript/ScriptUI的问题了,这让我非常困惑,我不得不求助于这里的专家。我想这意味着我在学习!:~)

下面是我正在努力工作的一段代码。理论上,它应该允许打开1、2或3个调色板窗口(取决于数组pSpecial中有多少true语句),然后等待用户在每个窗口中选择一些项目,然后单击第4个调色板中的Continue按钮。我为这件事的复杂性提前道歉。我对这一切还比较陌生,所以代码可能有点难理解,但可能可以归结为只打开一两个简单的调色板。

var aFoils = ["Choose one…", "-", "Shiny Gold", "Matte Gold", "Shiny Silver", "Matte Silver", "Copper", "Green", "Dark Purple", "Blue", "Teal", "Red", "Burgundy"];
var swatchObjects = ["123u", "871c", "Black"];
var pSpecial = [false, true, false];
// The xDelta variable specifies how far to move the palettes away from each other.
// xMove will be the X LOCATION for the new window.
var xDelta = 300;
var xMove;
var hsChecks = [], hsDropdowns = [], dbRadios = [], ebRadios = [];
var hotstampColors = [];
var debossColor, embossColor;
// If one of the specials is checked (hotstamp/deboss/emboss), then let's handle it.
// Define the Hotstamp window.
var hotstampWin = new Window("palette");
    hotstampWin.onShow = function ()
    {
        hotstampWin.location.x = xMove;
    }
    hotstampWin.add("statictext", undefined, "Please select Hotstamping foils:");
    var hsGroups = hotstampWin.add("group");
        var hsCheckGrp = hsGroups.add("group");
            hsCheckGrp.orientation = "column";
            hsCheckGrp.alignChildren = "left";
        var hsDDGrp = hsGroups.add("group");
            hsDDGrp.orientation = "column";
            hsDDGrp.alignChildren = "left";
            for (var h = 0; h < swatchObjects.length; h++)
            {
                hsChecks.push(hsCheckGrp.add("checkbox", undefined, swatchObjects[h]));
                hsDropdowns.push(hsDDGrp.add("dropdownlist", undefined, aFoils));
            }
// Define the Deboss window.
var debossWin = new Window("palette");
    debossWin.onShow = function ()
    {
        debossWin.location.x = xMove;
    }
    debossWin.add("statictext", undefined, "Please check which color is Debossed:");
    var dbGroup = debossWin.add("panel");
        for (var d = 0; d < swatchObjects.length; d++)
        {
            dbRadios.push(dbGroup.add("radiobutton", undefined, swatchObjects[d]));
        }
// Define the Emboss window.
var embossWin = new Window("palette");
    embossWin.onShow = function ()
    {
        embossWin.location.x = xMove;
    }
    embossWin.add("statictext", undefined, "Please check which color is Embossed:");
    var ebGroup = embossWin.add("panel");
        for (var e = 0; e < swatchObjects.length; e++)
        {
            ebRadios.push(ebGroup.add("radiobutton", undefined, swatchObjects[e]));
        }
// Define the window with the "Continue" button.
var continueWin = new Window("palette"/*, undefined, undefined, {borderless: true}*/);
    continueWin.onShow = function ()
    {
        continueWin.location.y = ($.screens[0].bottom / 2) - (continueWin.size[1] / 2) + 75 + (25 * swatchObjects.length);
    }
    var bContinue = continueWin.add("button", undefined, "Continue", {name: "ok"});
        bContinue.onClick = function ()
        {
            if (dbRadios.length > 0) {debossColor = selected_rbutton(dbGroup);}
            if (ebRadios.length > 0) {embossColor = selected_rbutton(ebGroup);}
            if (hsChecks.length > 0)
            {
                for (var j = 0; j < hsChecks.length; j++)
                {
                    if (hsChecks[j].value)
                    {
                        hotstampColors.push([swatchObjects[j], hsDropdowns[j].selection.text]);
                    }
                }
            }
            aSpecial[0].close();
            this.parent.close();
        }
function selected_rbutton (rbuttons)
{
    for (var i = 0; i < rbuttons.children.length; i++)
    {
        if (rbuttons.children[i].value == true) {return rbuttons.children[i].text;}
    }
}
var aSpecial = new Array;
if (pSpecial[0]) {aSpecial.push(hotstampWin);}
if (pSpecial[1]) {aSpecial.push(debossWin);}
if (pSpecial[2]) {aSpecial.push(embossWin);}
switch (aSpecial.length)
{
    case 1:
        aSpecial[0].show();
        xMove = ($.screens[0].right / 2) - (aSpecial[0].size[0] / 2);
        aSpecial[0].show();
        if (continueWin.show() == 1)
        {
            aSpecial[0].close();
            continueWin.close();
        }
        else
        {
            exit();
        }
        break;
    case 2:
        aSpecial[0].show();
        xMove = ($.screens[0].right / 2) - (aSpecial[0].size[0] / 2) - xDelta;
        aSpecial[0].show();
        aSpecial[1].show();
        xMove = ($.screens[0].right / 2) - (aSpecial[1].size[0] / 2) + xDelta;
        aSpecial[1].show();
        if (continueWin.show() == 1)
        {
            aSpecial[0].close();
            aSpecial[1].close();
            continueWin.close();
        }
        else
        {
            exit();
        }
        break;
    case 3:
        aSpecial[0].show();
        xMove = ($.screens[0].right / 2) - (aSpecial[0].size[0] / 2) - (xDelta * 1.5);
        aSpecial[0].show();
        aSpecial[1].show();
        xMove = ($.screens[0].right / 2) - (aSpecial[1].size[0] / 2);
        aSpecial[1].show();
        aSpecial[2].show();
        xMove = ($.screens[0].right / 2) - (aSpecial[2].size[0] / 2) + (xDelta * 1.5);
        aSpecial[2].show();
        if (continueWin.show() == 1)
        {
            aSpecial[0].close();
            aSpecial[1].close();
            aSpecial[2].close();
            continueWin.close();
        }
        else
        {
            exit();
        }
        break;
    default:
        break;
}

我对这段代码的问题是,当运行时,调色板打开,然后立即关闭。没有用户交互的机会。它们为什么关闭?

此外,我曾尝试将一个或多个窗口更改为dialog类型,但随后该窗口将接管,并且在该窗口被关闭之前不允许用户与任何其他窗口交互。

我也对其他想法持开放态度,比如将所有内容组合到一个对话框窗口中,但我希望它根据pSpecial数组中的"true"数量动态调整大小。

如果您从ESTK运行它,它就可以工作。至少在我的IDCC中。

但要使它从ID脚本面板运行,您必须添加:

#targetengine'foo';

在脚本的开头。(或任何其他目标引擎)请注意,在关闭InDesign之前,#targetengine 'foo'中的所有全局变量都将存在。因此,您应该将脚本封装到一个函数中。此外,我建议使用return而不是exit()