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

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
Roberto

Many thanks: you are right!
Unfortunately, I am at the very beginning with ExtendScript, and there are so many things I don't know until now...
With recompose() everything works very well, and it give me a solution also for redrawing the page while the script is working...
Many thanks, again!
Roberto

Similar Messages

Maybe you are looking for

  • MainStage 1.0.2 released

    MainStage 1.0.2 addresses specific customer issues and general performance issues and improves overall stability. This update is recommended for all MainStage users.

  • Aperture 3 - Continuous freezing and library updating

    Aperture seems great when it works but is updating my library of 6000 pictures regularly for no apparent reason and this at a speed of one picture every two seconds. The computer is a 3.06 GHz Intel Core 2 Duo with 8 GB 1067 MHz DDR3 and should be ab

  • Apps crash on startup after 7.03 update.

    I have tried resetting all settings, rebooted, and redownloading apps, but nothing seems to work.

  • Past Due Credit

    In March we traded our flip phones in for smartphones.  At that time they had a special going that we would receive $100 for each smartphone we purchased as well as the $35 activation fee waived for each phone.  It is now August and we have not recei

  • Sleep or dim screen?

    My iBook is about 3 yrs old now, and it is my only computer, which i use on and off all day, writing, internet, etc. i was wondering which is better for the life of both the whole computer and the backlight/display when i'm not using it--putting the