4 Replies Latest reply on Oct 18, 2018 5:10 AM by gabry-el

    InDesign ExtendScript stops before end

    gabry-el Level 1

      Hello everyone,


      I'm writing an ExtendScript Script for InDesign, to automatically build a catalog with a number of pages (that can range from 1 - single data sheet - to 600+ - complete products ecosystem).


      The problem is when I try to build the resource-heavy 600+ pages file. In fact, while the number of resources in RAM is limited (up to 800Mb), the execution is slow, since I need to perform several arrangements. After 30 minutes of InDesign working as expected, the script suddenly interrupts for no reason (or, at least, ESTK tells me this). Therefore I suppose there is some kind of script execution timeout.


      Is this plausible? Is there any way to set this timeout to, like, one hour? Or any workarounds?


      Thank you for your support.

        • 2. Re: InDesign ExtendScript stops before end
          gabry-el Level 1

          I'm not sure how this works. What is idleTask supposed to do? Should I create one for each "for" loop?

          I provide a sample of the code I'm using to better show how I wrote the script.


          var xmlElementsCount = app.activeDocument.xmlElements[0].count();
          var products = [];
          for ( var x = 0; x < xmlElementsCount; x++ ) {
               var xmlNode = app.activeDocument.xmlElements[0].xmlElements[x];
               // Place XML content for each node xmlNode; and arrange them following several rule to compose the page...
               // Also creates objects containing links, page numbers, etc. e.g.
               products = products.concat(new Product(productName, thisObj.parentPage.documentOffset+1, pictureLink, productCategory);
          // Creates a number of different TOCs based on products
          var pLength = products.length;
          for ( var p = 0; p < pLength; p++ ) {
               while ( products[p].productCategory === categoryListItem ) {
                    // Creates a textFrame through Product object method, places it into page, etc...


          Given this short sample which I hope is exhaustive (the real code is 2000+ lines I did not reproduce for clarity's sake), can you please tell me how to implement idleTask? As you can see, I cannot determine a priori the exact execution time of each for or while loop, since lots of different rules and variables are involved (e.g. some products will have no image to handle, some others will have 2, some will have 10...)

          • 3. Re: InDesign ExtendScript stops before end
            Dirk Becker Level 4

            Save your document every few pages.

            If the output of $.summary() gets too large, $.gc() might help.

            Have a look at the undo modes of app.doScript().

            2 people found this helpful
            • 4. Re: InDesign ExtendScript stops before end
              gabry-el Level 1

              Thank you; not really sure about how the garbage collection works - I'm not yet a coding pro (tbh, I'm just a graphic designer with mediocre coding skills trying to do a complex automation).
              However, I tried implementing doScript() with UndoMode.ENTIRE_SCRIPT, and it really improved execution time and memory management (don't know why I didn't think about using this before).

              I'll be doing some further research on garbage collection to manage this even better.

              Thank you a lot.



              As suggested by Dirk, whom I sincerly thank, saving every few tasks and issuing garbage collection works. Also setting undo mode to "entire script", and applying it to the most resource demanding tasks collected as functions, it helps a lot.