OK, I think I have isolated the problem condition. If I run the script right after I open the document, the script makes the document dirty. When I undo the script, the document is no longer dirty (and thus I can't revert to saved). This is where the script error occurs if I run the script again. If the document is already dirty when I run the script, and I undo it the document is still dirty. I run the script again, and there are no errors.
I don't think this will be quite as easy to troubleshoot. My bare bones script does not duplicate the problem. In the bare bones script, I am touching every table in the document by adding 1mm to its first column width. When I undo it and rerun it, I get no errors. However, my production script does quite a bit more: it tests for a particular kind of table, and for these, it adds a table column, some content to the column, sets borders on the new column, and proportionately scales the table to the text column width. Somewhere along the line, some instability is introduced that causes the table collection to become invalid after an undo to an unsaved document state.
If anyone is interested in testing the entire script, you download it here:
When you run the script on the document, you will prompted for a CSV file, which is included in the archive. The script looks for parts tables and updates the prices based on the contents of the CSV file. It also populates a Product Group column, which it creates if it doesn't exist in the table. Thank you very much.
Message was edited by: frameexpert
I cannot try your sample 'cause it's a CS 5.5 document and I'm at home, but browsing the script this caught my eye:
You process a Book's worth of documents by opening, changing, then saving and closing its individual documents. InDesign, however, does not store its "Undo" information along with each document. I would have guessed attempting to Undo stuff done in a now-closed document would fail silently, but apparently this is unexpected enough to make ID clench its jaws and mess up the Undo's in your current document.
Do you get the same erratic behavior if you stick to the pragmatic "You Can Only Undo Stuff In Your Current Document"?