The repeat loop in script exports the stories based on their ID, so the export is in order of the story creation not its position in the layout.
It wouldn't be too hard to alter the script so that it loops a page at a time so at least the page order would be maintained. A story at the bottom of the page might still be ahead of a story at the top of the page. A script that checks for left-to-right, top-to-bottom would be more difficult but possible.
What Rob said. Each time a new object is added to an InDesign document, InDesign assigns it its own unique ID number - the higher the number, the later it was created. It makes sense that your TOC would be one of the last things created, after the rest of your content.
If you can spend a few bucks ($19), you might give Rorohiko's Text Exporter a try. It has some nice options for setting the order in which text frames are read and how it exports the text. Check out the Manual page for a better idea of what it does:
I use Rorohiko's TextStitch - which is free. Many of the documents I handle are so, um, er, idiosyncratic in layout structure that there's no way to programatically harvest all text frames in logical reading order without having a human sort them out. So I use TextStitch to thread the frames by hand - which is quite easy, just one click per frame, much easier than doing so by inserting frame breaks and connecting out-ports to in-ports.
I'd happily pay for a version that had TextExport's options settings, as I wind up doing a bunch of programmatic un-grouping and un-threading before I can use TextStitch. It's still faster for me than working any other way, though.
Thank you all. Yes, I'm actually using Rohohiko's TextExporter now. I believe it does the best job. I've also tried Recosoft's, but, its RTF is too fancy for my company's SGML gateway. Our publishing system is a Unix-Based SGML system, so, we send RTF files through a "gateway" that converts it to SGML. The Recosoft RTF won't go through, probably because our gateway was written 15 years ago. Manually exporting to RTF within InDesign to RTF worked. The scripts messed up the order, as I said, so, I don't think it's worth using them. I'm talking about InDesign files that are from the universe, not from my world. I didn't make them.
The scripts messed up the order, as I said, so, I don't think it's worth using them. I'm talking about InDesign files that are from the universe, not from my world. I didn't make them.
This version of the applescript exports by the page with the page number as the filename prefix