medos20

Global Variables only Called Once then Lost their Scope

Aug 3rd, 2021
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Global Variables only Called Once then Lost their Scope!
  2. #targetengine "session1";
  3. var w = new Window("palette", {independent:true}); //Main Palette Windows
  4. var findoptions = new Window("palette"); //Options Palette
  5.  
  6. function Main() {
  7.     // Check to see whether any InDesign documents are open.
  8.     // If no documents are open, display an error message.
  9.     if (app.documents.length > 0) {
  10.         var myDoc = app.activeDocument;
  11.     }else{
  12.         // No documents are open, so display an error message.
  13.         alert("No InDesign documents are open. Please open a document and try again.");
  14.     }
  15. }
  16.  
  17. //---------------------------------------------------------
  18. //Making Palettes Windows
  19. //---------------------------------------------------------
  20. #targetengine "session1";
  21. var w = new Window("palette", {independent:true}); //Main Palette Windows
  22. var findoptions = new Window("palette"); //Options Palette
  23. //gqmanager is the (GREP Query Manager) outside the main Function
  24. w.text = "Test the Connection Between Global Variables and Palettes";
  25. w.preferredSize.width = 500;
  26. w.alignChildren = ["center", "center"];  //"left";
  27. w.orientation = "column"; //"row";
  28. w.spacing = 10;
  29. w.margins = 16;
  30.  
  31. //Parent - Input Panel Prepare
  32. var InputPanel = w.add("panel", undefined, undefined, { name: "panel1" });
  33. InputPanel.text = "Text Find : ";
  34. InputPanel.preferredSize.width = 1000;
  35. InputPanel.orientation = "row";
  36. InputPanel.alignChildren = ["center", "center"];
  37. InputPanel.spacing = 10;
  38. InputPanel.margins = 16;
  39.  
  40. //Children -  input Panel Inside Prepare
  41. var myInputPanelInside = InputPanel.add("group", undefined, { name: "myInput" });
  42. //--Adding Find What
  43. myInputPanelInside.add("statictext", undefined, "Find What :");
  44. //myInputPanelInside.alignment = "center";
  45. var myGREPString = myInputPanelInside.add("edittext", undefined, "SAMPLE");
  46. myGREPString.helpTip = "Enter Your Text"
  47. myGREPString.characters = 20;
  48. myGREPString.enabled = true;
  49. myGREPString.preferredSize.width = 460;
  50.  
  51. var Button1 = myInputPanelInside.add("button", undefined, "Options");
  52.  
  53. //Parent - Radio Panel Prepare
  54. var RadioPanel = w.add("panel", undefined, undefined, { name: "panel2" });
  55. RadioPanel.text = "Select Desired Option : ";
  56. RadioPanel.preferredSize.width = 1000;
  57. RadioPanel.orientation = "row";
  58. RadioPanel.alignChildren = ["center", "center"];
  59. RadioPanel.spacing = 10;
  60. RadioPanel.margins = 16;
  61.  
  62. //Children -  input Panel Inside Prepare
  63. var myRadioPanelInside = RadioPanel.add("group", undefined, { name: "myRadio" });
  64. myRadioPanelInside.preferredSize.width = 500;
  65. myRadioPanelInside.alignChildren = ["center", "center"];
  66.  
  67. //Adding Radio Buttons
  68. var radio1 = myRadioPanelInside.add("radiobutton", undefined, "Option 1");
  69. var radio2 = myRadioPanelInside.add("radiobutton", undefined, "Option 2");
  70. var radio3 = myRadioPanelInside.add("radiobutton", undefined, "Option 3");
  71. radio1.preferredSize.width = 200;
  72. radio2.preferredSize.width = 200;
  73. radio3.preferredSize.width = 200;
  74. //Previous Default Condition
  75. radio1.value = true;
  76.  
  77. var myButtonGroup = w.add("group");
  78. myButtonGroup.alignment = "center";
  79.  
  80. var Button2 = myButtonGroup.add("button", undefined, "Show Alert Due Options");
  81. var Button3 = myButtonGroup.add("button", undefined, "Exit");
  82.  
  83. Button1.onClick = function () {
  84.     CalltheFindOptions();
  85.     }
  86. Button2.onClick = function () { Find(); };
  87. function Find() {
  88.     doRadioButtonOpt();
  89. }
  90.  
  91. Button3.onClick = function() {Canceled();};
  92. function Canceled() {
  93.     ExitSure();
  94. }
  95.  
  96. //After Drawing Interface
  97. var a = w.show();
  98.  
  99. function ExitSure() {
  100.   var a = w.close();
  101.   exit(0);
  102. }
  103.  
  104. //User Selection for Radio Buttons
  105. function doRadioButtonOpt() {
  106.     myDoc = app.activeDocument;
  107.   if (radio1.value == true) {
  108.     TestVars();
  109.     }
  110. }
  111.  
  112. function TestVars() {
  113.     #targetengine "session1";
  114.     var myDoc = app.activeDocument
  115.     var TimeMs = Number(SliderControlText.text); //Converting Text to Number
  116.     //Show Results Found as User Wish
  117. if (DontShowResults.value == true) { //no Show only Apply
  118.     alert("you Select not to Show Results!");
  119.             }else{ //Direct Show and Apply
  120.         if (ShowResultsDirect.value == true) {
  121.     alert("you Select to Show Results in real time!");
  122.             }else{ //Show and Apply By WaitinhTime!
  123.                 if (ShowResults.value == true) { //Show and Apply
  124.             alert("you Select to Show Results with Specific time!");
  125.             $.sleep(TimeMs); //Wait ms
  126.                     }
  127.                 }
  128.             }
  129. alert("Do you need somthing else?, try again", "Finish Report");
  130. }
  131.  
  132. var DontShowResults;
  133. var ShowResultsDirect;
  134. var ShowResults;
  135. var SliderControlText;
  136. var slider;
  137. //--------------------------------------------Building the Find Options Palette-----------------------------------------//
  138. //--------------------------------------------------------------------------------------------------------------------------------//
  139. function CalltheFindOptions() {
  140. #targetengine "session1";
  141. //Find Options Window
  142. findoptions.text = "Find Options";
  143. //Parent - Input Panel Prepare
  144. SelectPanel = findoptions.add("panel", undefined, undefined, { name: "panel1" });
  145. SelectPanel.text = " Find Options : ";
  146. SelectPanel.preferredSize.width = 1000;
  147. SelectPanel.orientation = "row";
  148. SelectPanel.alignChildren = ["center", "center"];
  149. SelectPanel.spacing = 10;
  150. SelectPanel.margins = 16;
  151.  
  152. //Children -  input Panel Inside Prepare
  153. mySelectPanelInside = SelectPanel.add("group", undefined, { name: "mySelOpt" });
  154. DontShowResults = mySelectPanelInside.add("checkbox", undefined, "Don't Show Results");
  155. DontShowResults.value = true; //by Default
  156. DontShowResults.alignment = "left";
  157.  
  158. ShowResultsDirect = mySelectPanelInside.add("checkbox", undefined, "Show Results");
  159. ShowResultsDirect.value = false; //by Default
  160.  
  161. ShowResults = mySelectPanelInside.add("checkbox", undefined, "Show Results Delayed in milliseconds(Ms) :");
  162. ShowResults.value = false; //by Default
  163.  
  164. //Adding Slider to Control MS Time
  165. SliderControlText = mySelectPanelInside.add ("edittext", undefined, 10, {readonly: false}); //read only prevent user Entering Nums
  166. SliderControlText.characters = 3;
  167. slider = mySelectPanelInside.add ("slider {minvalue: 1, maxvalue: 100, value: 10}");
  168.  
  169. //Slider Listener Plus SliderControl Text Listener
  170. slider.onChanging = function () {SliderControlText.text = slider.value;} //Listen to Slider
  171. var c = findoptions.show();
  172. }
RAW Paste Data