Pregunta

It's been a while since I've had a problem with ExtendScript / ScriptUI that's boggled me enough that I've had to turn to the experts here. I suppose that means I'm learning! :~)

The following is a snippet of code that I'm trying to get to work. Theoretically, it should allow 1, 2, or 3 palette windows (depending on how many true statements are in the array pSpecial) to open, then wait for the user to select some items in each of them and click the Continue button in the 4th palette. I apologize in advance for the complexity of this one. I'm still relatively new to all of this, so the code might be a bit hard to follow, but it could probably be boiled down to just having one or two simple palettes open.

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;
}

The problem I'm having with this code is that, when run, the palettes open, then immediately close. There's no chance for user interaction. Why do they close?

Also, I've tried change one or more of the windows to the dialog type, but then that window takes over and doesn't let the user interact with any others until that one is dismissed.

I'm also open to other ideas, such as combining everything into one dialog window, but then I'd want it to size dynamically depending on how many "true"s there are in that pSpecial array.

¿Fue útil?

Solución

If you run it from ESTK it works. At least in my IDCC.

But to make it run from the ID Scripts Panel you have to add:

#targetengine'foo';

at the beginning of your script. (or any other targetengine) Be aware that all globals in the #targetengine 'foo' will exist until you close InDesign. So you should wrap your script into a function. Also I would recommend using return instead of exit()

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top