我已经有一段时间了,因为我遇到了ExtendScript / ScriptUI的问题,这让我很难过,所以我不得不求助于这里的专家。我想这意味着我正在学习! :〜)
以下是我试图开始工作的一段代码。从理论上讲,它应该允许1,2或3个调色板窗口(取决于数组true
中有多少pSpecial
个语句)打开,然后等待用户在每个窗口中选择一些项目然后单击第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
类型,但随后该窗口接管并且不允许用户与其他任何人交互,直到该窗口被解除。
我也对其他想法持开放态度,例如将所有内容组合到一个对话框窗口中,但我希望它根据{{1}中有多少“true
”来动态调整大小。数组。
答案 0 :(得分:2)
如果你从ESTK运行它可以工作。至少在我的IDCC中。
但要从ID Scripts Panel运行它,你必须添加:
#targetengine'foo';
在脚本的开头。 (或任何其他目标引擎)请注意,#targetengine 'foo'
中的所有全局变量都将存在,直到您关闭InDesign。所以你应该将脚本包装成一个函数。另外,我建议使用return
代替exit()