3 Replies Latest reply on Dec 25, 2011 5:16 PM by [Jongware]

    Undo clobbers script variables

    frameexpert Level 4

      This one is not related to the fastEntireScript versus entireScript issue, because I am using entireScript. Here is the scenario. I have a script that processes a bunch of tables in the document. I run the script, undo it, and then run it again. The second time it is run, one of the table variables in my collection becomes invalid and stops the script with an error when I try to access its first row. If I make the document dirty and revert to saved before running the script the second time, I don't get the error. Or, if I quit and restart InDesign, I don't get the error. It seems that the undo is leaving the document or scripting engine in an unstable state. Here is my doScript call:


      app.doScript(main, undefined, undefined, UndoModes.entireScript,"Update Price Tables");


      The script is quite large, so I am going to pare it down to bare bones and see if it still occurs. I will post the test script shortly.


      I am using InDesign 5.5. Thank you very much.


      Rick Quatro

        • 1. Re: Undo clobbers script variables
          frameexpert Level 4

          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.

          • 2. Re: Undo clobbers script variables
            frameexpert Level 4

            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

            • 3. Re: Undo clobbers script variables
              [Jongware] Most Valuable Participant

              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"?