• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Completing track changes before export

New Here ,
Nov 19, 2016 Nov 19, 2016

Copy link to clipboard

Copied

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? 

TOPICS
Scripting

Views

482

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2016 Nov 20, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 21, 2016 Nov 21, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 21, 2016 Nov 21, 2016

Copy link to clipboard

Copied

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 21, 2016 Nov 21, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 21, 2016 Nov 21, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 22, 2016 Nov 22, 2016

Copy link to clipboard

Copied

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.everyItem().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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 22, 2016 Nov 22, 2016

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines