2013-08-29 65 views
0

自從我遇到ExtendScript/ScriptUI問題時,已經有一段時間了,我覺得這足夠讓我不得不轉向這裏的專家。我想這意味着我正在學習! :〜)InDesign 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類型,但隨後該窗口接管並且不讓用戶與其他任何人交互,直至該人被解僱。

我也接受其他想法,例如將所有內容合併到一個對話窗口中,但是我希望它的大小可以動態調整,具體取決於該數組中有多少個「true」。

回答

2

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

但要讓它從你必須添加ID腳本面板運行:在你的腳本的開頭

#targetengine'foo'; 

。 (或任何其他目標引擎)請注意,在關閉InDesign之前,#targetengine 'foo'中的所有全局變量都將存在。所以你應該把你的腳本包裝成一個函數。此外,我會推薦使用return而不是exit()

+0

我們在這裏只有InDesign CS6,它正在從腳本面板_and_ ESTK展示該行爲。您的補充允許它現在工作,謝謝。 我假設,'globals'指的是在腳本開頭聲明的所有變量,以及腳本前半部分定義的四個調色板。那麼,它將全部包裝在主腳本中的一個函數中,所以我認爲它是很好的。 我想我可能會重新做這整個事情,把它全部放在一個'對話框'窗口中,因爲我有一些想法使它不那麼難看。感謝您的幫助,@fabiantheblind! – Sturm