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

  • Issue with Logitech Bluetooth mouse

    Hi everyone! I have some problems in correctly configuring my Logitech v270 bluetooth mouse. I followed all the steps in http://wiki.archlinux.org/index.php/Bluetooth_Mouse, but I still can't connect automatically at startup. Each time I boot my lapt

  • Solaris 10 Openssh v5.3p1 sftp chroot works but denied permission

    Hi all, I have been working for 3 days to make chroot work on Solaris 10 with openssh v5.3p1 usring http://www.minstrel.org.uk/papers/sftp/builtin/ methods. All looks great, I can open a sftp session but when I try to write I get permissin denied mes

  • Is my iPod broken?

    I was listening to my iPod when all of a sudden it turned off and it will not turn back on. I've tried charging it and plugging it in my computer but it still won't turn on. Is it broken?

  • Copy phone number from Address Book dashboard widget?

    Is there any way to copy a phone number directly from the address book widget?

  • Wi-fi issues after updating to iOS 6 (SOLVED!)

    If you are having an issue over the wi-fi connection after updating to iOS 6, where the log-in to your wi-fi network fail and send you to an Apple web page, this is how I solved it: Turn of your iPhone, not restart or restore, just turn it off, wait