2

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

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

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类型,但随后该窗口接管并且不允许用户与任何其他窗口交互,直到该窗口被关闭。

我也对其他想法持开放态度,例如将所有内容组合到一个对话框窗口中,但是我希望它根据该数组true中有多少“”来动态调整大小。pSpecial

4

1 回答 1

3

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

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

#targetengine'foo';

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

于 2013-08-30T07:23:17.037 回答