-
1. Re: Problems with accessing all text in a document
[Jongware] Dec 15, 2010 2:18 PM (in response to FrankB62)Can you test with Export this file to IDML, open the exported one, and then try any or all of your scripts? (Be careful not to overwrite your original file. IDML is reported to have a "100% safe round-trip" -- per the latest update. I think they said the same before that update.)
The reason is that your code looks good and ought to have worked just fine; and you thoughtfully mentioned the file wasn't originally created inside InDesign. At times, pieces of a document go a-float and ID cannot reliably tack them together; exporting, then importing again ought to free all debris.
(I just thought of this: a quicker method could be to "Save As" your file. It clears out most of the file, where exporting/importing does a more thorough job but takes longer. So you could just this one a first try.)
-
2. Re: Problems with accessing all text in a document
FrankB62 Dec 17, 2010 6:29 AM (in response to [Jongware])I have tried exporting as IDML, but it makes no difference.
I then tried constructing my loop using item index instead, and it gives an interresting result:
For StoryNo = 1 To Document.Stories.Count
Set Story = Document.Stories.Item(StoryNo)Story.Contents = ""
Next
Document.Stories.Count is 1434 when I start this loop, but when the index reaches 30, it is changed to 1076, and stays at that value through the rest of the loop (and the script gives an error, of course, when the index goes out of bounds).
If I loop backwards instead (Step -1), then it works, and all text in the document is deleted.
My conclusion is that there is something severely wrong with the document, and the various collections are not set properly.
-
3. Re: Problems with accessing all text in a document
[Jongware] Dec 17, 2010 6:34 AM (in response to FrankB62)If counting backwards works, then use that. Some object manipulations may change the internal state of ID's object counters, and you'll get unreliable results trying to work from start to end.
An afterthought: did you have anchored objects in your original text? Text inside these also count as a separate story, but it's removed when you empty out its parent story -- thus, possibly, throwing off the original counts.
-
4. Re: Problems with accessing all text in a document
FrankB62 Dec 17, 2010 6:51 AM (in response to [Jongware])There are anchored objects in the document (more than 3000), but none of those are removed by my script. The story count only changes once (from 1434 to 1076) when I clear one specific story, so to me it look like there is something wrong internally with that collection, and InDesign repairs it on the way.
I am going to make some tests with looping backwards, but I am certainly not comfortable with the whole situation. Who knows what else could be wrong with that document.
-
5. Re: Problems with accessing all text in a document
FrankB62 Dec 17, 2010 7:02 AM (in response to FrankB62)Also note: My example with clearing all text within each story is only a debug method to find out where things go wrong. The real scenario is to change the text within specific pharagraphs, but that makes no difference to how the looping through stories work. With my For Each loop through the stories (case A), it only changes text in paragraphs on the first 47 pages, same as my example script only deletes text on the first 47 pages.