12 Replies Latest reply on Nov 15, 2016 9:35 AM by Bernd Alheit

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

    ben92691


      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.

        • 1. Re: Dialog (app.execDialog()) doesn't open second time i run the script
          George_Johnson MVP & Adobe Community Professional

          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.

          • 2. Re: Dialog (app.execDialog()) doesn't open second time i run the script
            ben92691 Level 1

            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

            • 3. Re: Dialog (app.execDialog()) doesn't open second time i run the script
              George_Johnson MVP & Adobe Community Professional

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

              • 4. Re: Dialog (app.execDialog()) doesn't open second time i run the script
                ben92691 Level 1

                No error codes are printing even though the code to show the dialog is in a try-catch block.  The println-s that do print seem to indicate that something goes wrong at the moment the dialog should open and then the script begins the next iteration.

                • 6. Re: Dialog (app.execDialog()) doesn't open second time i run the script
                  try67 MVP & Adobe Community Professional

                  Do you mean that it doesn't show up multiple times in your do-while loop (which I don't quite understand... If you want to prevent the user from going forward unless they fill in all of the required information then you should enforce that in the dialog itself, using the validate event), or that it only shows up for the first file you're processing?

                   

                  Also, the trim() method is not supported in Acrobat JS, as far as I know. You'll need to use your own trim function.

                  • 7. Re: Dialog (app.execDialog()) doesn't open second time i run the script
                    ben92691 Level 1

                    The code is running from an action inside Acrobat DC.  The first time I process some files, I see the dialog.  But when I run the action on a second set of files, the dialog does not display.

                    • 8. Re: Dialog (app.execDialog()) doesn't open second time i run the script
                      ben92691 Level 1

                      See my reply about using an action.  The trim function does work.  Thanks for the tip about using the validate function, I'll need to look into that.

                      • 9. Re: Dialog (app.execDialog()) doesn't open second time i run the script
                        Bernd Alheit Adobe Community Professional & MVP

                        May be that the second time the global.counter is not undefined.

                        • 10. Re: Dialog (app.execDialog()) doesn't open second time i run the script
                          try67 MVP & Adobe Community Professional

                          ben92691 wrote:

                           

                          But when I run the action on a second set of files, the dialog does not display.

                          Of course not, because you added a condition that the dialog should only be displayed if global.counter is undefined, and you're defining it with in the first run of the code...

                          1 person found this helpful
                          • 11. Re: Dialog (app.execDialog()) doesn't open second time i run the script
                            ben92691 Level 1

                            global.counter gets deleted at the end of script, when it matches global.FileCount.

                             

                            The script has a number of println statements and when I run it a second time, according to what is printed in the console, it makes it into this if block (global.counter undefined), yet the dialog does not display.