7 Replies Latest reply on Nov 22, 2016 10:42 AM by Jump_Over

    Completing track changes before export

    indesignusercs6

      I am trying to accept all changes in a document, and then export the result to IDML.  (goal is to perform the task on a batch of files at the same time).

       

      I am using the following code:

       

      app.documents[0].stories.everyItem().changes.everyItem().accept();

      exportIdm(app.documents[0]);

      function exportIdml(theDocument)

      {

            myFilePath = theDocument.name + ".idml";

            myFile = new File(myFilePath);

            theDocument.exportFile(ExportFormat.INDESIGN_MARKUP, myFile, false);

      }

       

      If I try only to accept all changes, or simply to export IDML, with part of the above code, I get expected result.

      However, if I run both in the same script, InDesign hangs, and I get an invalid frame when InDesign restart and recover the document.

      It looks like the app.documents[0].stories.everyItem().changes.everyItem().accept() action is not completely committed before the next function is called.

       

      Note that in my test document, there are a large number of changes, including over 600 frames tracked for deletion, which can be a contributing factor.

       

      Any clue on how I can force the accept() to complete and commit the changes before running the IDML export? 

        • 1. Re: Completing track changes before export
          Peter Kahrel Adobe Community Professional & MVP

          You can make the script wait for a few seconds:

           

          $.sleep (n);

           

          where n is the number of milliseconds to wait.

           

          By the way, myFilePath = theDocument.name + 'idml' is misleading in that you return the document's name without the path.

           

          Peter

          • 2. Re: Completing track changes before export
            indesignusercs6 Level 1

            Thank you for your input, but that did not help.

            I also tried to save the document from within the script, but with similar results..

             

            As a side note, the file path info shown in my example is not in the final format.  In the full program, I perform the idml export for an entire folder, where I include the full path for that folder.  This complete program works well if I only perform the idml export, but fail if I add the line to accept all the changes.

            • 3. Re: Completing track changes before export
              tpk1982 Level 4

              What will happen to do like below?

               

              exportIdm(app.documents[0]);

              function exportIdml(theDocument)

              {

                     app.documents[0].stories.everyItem().changes.everyItem().accept();

                         myFilePath = theDocument.name + ".idml";

                    myFile = new File(myFilePath);

                    theDocument.exportFile(ExportFormat.INDESIGN_MARKUP, myFile, false);

              }

              • 4. Re: Completing track changes before export
                indesignusercs6 Level 1

                That does not work either.  It almost look like there is some kind of final cleanup or final commit of the changes that only happens when returning to the user prompt, and that is required between the accept() and further functions.

                • 5. Re: Completing track changes before export
                  Jump_Over Level 5

                  Hi,

                   

                  Is it work without export?

                  Can you compare

                  app.documents[0].stories.everyItem().changes.everyItem().getElements().length

                  at start and end point (without export)?

                  Let say inserting alert...

                   

                  Jarek

                  • 6. Re: Completing track changes before export
                    indesignusercs6 Level 1

                    Jarek,

                     

                    I have tested the following code and it behaves as expected, as long as I do not issue an export afterward:

                            alert("There are " + app.documents[0].stories.everyItem().changes.length + " changes in document " + app.documents[0].name);

                            app.documents[0].stories.everyItem().changes.everyItem().accept();

                            alert("Accept Finished");

                            alert("There are " + app.documents[0].stories.everyItem().changes.length + " changes in document " + app.documents[0].name);

                     

                    The first alert shows 172 changes.   And the second one shows 0 change left in the document.

                    But if I include export immediately after the last alert, InDesign hangs again.

                     

                    I have tried several other function call after accept and they all fail:

                    theDocument.exportFile(ExportFormat.INDESIGN_MARKUP, myFile, false);  -->  InDesign hang

                    theDocument.save()  --> InDesign hang

                    app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().changes.everyIte m().accept();  --> Generate an error that item no longer exists.   (which would confirm my suspicion that the first set of changes are not fully "committed" when the next function call is made).

                     

                    • 7. Re: Completing track changes before export
                      Jump_Over Level 5

                      Hi,

                       

                      I suggest to accept changes step by step using a loop (instead of global 'everyItem()').

                      Including progressbar could be helpfull...:)

                       

                      Does your stories contain many/any tables?

                       

                      Is your code run by app.doScript(main,......., UndoModes.FAST_ENTIRE_SCRIPT,.....)?

                       

                      Jarek