3 Replies Latest reply on Aug 18, 2014 12:00 PM by eutheneia

    Text flows create a delay when an overflow creates a new page, preventing you from reading the page number, giving error

    eutheneia Level 1

      Hi all!

      I am creating a script to generate automatically a photo catalog; the idea is to prepare a master document with a text frame in the master spread with auto flowing, then insert images with their caption by the script, letting the system create automatically the subsequent pages when necessary by an unique flow of text.

      My catalog is divided in sections, each represented by a different master spread; so I have to know in which page I am working when the script put there an image, just to link the current page to the proper master spread.

      To simplify everything I have resumed the core of my script here, using text instead of images:


      /* load a master document, only containing an empty text frame in the master spread, connected to the main text flow */

      var doc = app.open(new File("~/Desktop/mySampleDoc.indd"));


      /* I work on the story, thinking that whenever the textframe of the first page will be full, another text frame will be created in the next page (automatically created) */

      var story = doc.pages[0].textFrames[0].parentStory;


      /* now I put some lines of text into the story, expecting the creation of a new page when the first one will be full */

      for (var i = 0; i < 100; i++) {

         /* this is next line: */

          story.insertionPoints[-1].contents = "this is line n. " + i + "\r";


          /* here I want to know on which page is the line just created (error is generated here just during the creation of the new page + text frame) */

          thisPage = story.insertionPoints[-1].parentTextFrames[0].parentPage.documentOffset;


         /* and now I print page number */

          story.insertionPoints.item(-1).contents = "current page: " + thisPage + "\r";



      The big problem is: when the first text frame is full and an overflow is generated, a new page with a new text frame belonging to the main text flow (as the master spread wants) is generated; but it seems my script requests the page number before the new page with the new text frame is born, and an error is given.

      It seems like the script goes too fast in respect to the creation of the new page.

      If I delete the line thisPage = story.insertionPoints[-1].parentTextFrames[0].parentPage.documentOffset; everything is ok.

      I tried to introduce a delay until 3 seconds without any effect.

      I tried also to show or zoom the new page before the page number request, thinking to force the system to wait until page is really born, also without any effect (by the way, I was not able to show the page during the script's additions of text!).


      Someone can help me?


      Many thanks to everyone