Skip to main content
ben92691
Participating Frequently
November 10, 2016
Question

Dialog (app.execDialog()) doesn't open second time i run the script

  • November 10, 2016
  • 1 reply
  • 1562 views


Everything works fine the first time.  The second time it runs but the dialog doesn't open and the scripts begins using the second PDF.

This topic has been closed for replies.

1 reply

Inspiring
November 10, 2016

You need to provide a lot more details, the script you're using in particular. It would also help to know what version of Acrobat/Reader you're using, and what OS.

ben92691
ben92691Author
Participating Frequently
November 11, 2016

I'm using Acrobat DC and Windows 10.

Here's the script:

/* Put script title here */
var dialogExh =
{
   initialize: function(dialog)
   {
      // Set default values
      dialog.load(
      {
         "sNum": global.startNum,
         "fSze": global.FontSize,
         "oTxt": global.Label,
         "eNum": global.endNum
      });
   },
   // called when OK pressed
   commit:function (dialog)
   {
      var selections = dialog.store();
      global.startNum = selections["sNum"];
      global.counter = selections["sNum"]-1;
      global.endNum = selections["eNum"];
      global.FontSize = selections["fSze"];
      global.Label = selections["oTxt"].trim();

   },
   destroy:function(dialog)
   {
      console.println("Destroy.");
   },
   description:
   {
      // Dialog box title
      name: "Sequential Slip Sheets - [ALL FOUR BOXES MUST BE FILLED IN]",
      first_tab: "eNum",
      align_children: "align_top",
      bold: true,
      width: 250,
      height: 200,
      elements:
      [
         {
            alignment: "align_left",
            type: "ok_cancel",
            ok_name: "OK",
            cancel_name: "Cancel"
         },
         {
            type: "cluster",
            name: "Label - [ALL BOXES MUST BE FILLED IN]",
            align_children: "align_left",
            elements:
            [
               {
                  item_id: "oTxt",
                  type: "edit_text",
                  alignment: "align_fill",
                  width: 100,
                  height: 20,
               },
               {
                  type: "view",
                  align_children: "align_row",
                  elements:
                  [
                     {
                        type: "static_text",
                        name: "Font Size: ",
                        alignment: "align_left",
                     },
                     {
                        item_id: "fSze",
                        type: "edit_text",
                        alignment: "align_left",
                        width: 50,
                        height: 20,
                     },
                  ]
               },
            ]
         },
         {
            type: "cluster",
            name: "Exhibit Numbers",
            align_children: "align_left",
            elements:
            [
               {
                  type: "view",
                  align_children: "align_row",
                  width: 138,
                  elements:
                  [
                     {
                        type: "static_text",
                        name: "Starting Num: ",
                        alignment: "align_left",
                     },
                     {
                        item_id: "sNum",
                        type: "edit_text",
                        alignment: "align_fill",
                        width: 50,
                        height: 20,
                     },
                  ]
               },
               {
                  type: "view",
                  align_children: "align_row",
                  width: 138,
                  elements:
                  [
                     {
                        type: "static_text",
                        name: "Ending Num: ",
                        alignment: "align_left",
                     },
                     {
                        item_id: "eNum",
                        type: "edit_text",
                        alignment: "align_fill",
                        width: 50,
                        height: 20,
                     },
                  ]
               },
            ]
         }
      ]
   }
};

// Begin job
try {
   if ( typeof global.counter == "undefined" )
   {
      console.println("Begin Job Code");
      global.counter = 0;
      global.startNum = "1";
      global.endNum = "";
      global.FontSize = "40";
      global.Label = "Exhibit";
      console.println("Before Do");
      do
      {
         try
         {
           console.println("Display dialog 1.");
           dialogResult = app.execDialog(dialogExh);
           console.println(dialogResult);
         }
         catch (err)
         {
             console.println("Error Message:  " + err);
         };
         if (dialogResult != "ok")
         {
            throw "Script cancelled.";
         };
         console.println("Display dialog 2.");
      }
      while ( global.Label == "" || global.startNum == "" || global.endNum == "" || global.FontSize == "" );
      global.FileCount = Number(global.endNum) - Number(global.startNum) + 1;
      confirmNum = app.alert(
      {
         cTitle:  "PLEASE CONFIRM",
         nIcon:  3,
         nType: 1,
         cMsg:  "Number of PDFs to process:  " + global.FileCount
      });
      if ( confirmNum == "2" )
      {
          throw "Script cancelled.";
      }; 
   // insert beginJob code here
   };
   global.counter++;
   console.println("Processing File #" + global.counter);
      //insert blank page as new page 1 of the PDF
   this.newPage(0);
   var annot = this.addAnnot
      ({
  page: 0,
  type: "FreeText",
         rect: [72,360,540,576],
         width: 0,
      });
   annot.textFont = "TimesNewRoman";
   var spans = new Array();
   spans[0] = new Object();
   spans[0].text = global.Label + " " + global.counter;
   spans[0].textColor = color.black;
   spans[0].textSize = Number(global.FontSize);
   spans[0].fontWeight = 700;
   spans[0].alignment = "center";

   // Now give the rich field a rich value
   annot.richContents = spans;

   this.flattenPages({
        nStart: 0,
      });
   } catch(e) {
         console.println("Batch aborted on run #" + global.counter);
         delete global.counter; // Try again, and avoid End Job code
         if ( typeof global.FileCount != "undefined" )
         {
            delete global.FileCount;
         }
         event.rc = false; // Abort batch
};
if ( global.counter == global.FileCount )
{
   if ( typeof global.counter != "undefined" )
   {
      console.println("End Job Code");
      // Remove any global variables used in case user wants to run
      // another batch sequence using the same variables
      console.println(global.counter);
      delete global.counter;
   };
   if ( typeof global.FileCount != "undefined" )
   {
      // Remove any global variables used in case user wants to run
      // another batch sequence using the same variables
      console.println(global.FileCount);
      delete global.FileCount;
   };
};
// End job

Inspiring
November 12, 2016

Do you see anything reported in the JavaScript console (Ctrl + J)?