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

Tables after data merge are not in right order.

New Here ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Hello, I am writing with a request for help with data merging.

When I multiple records on more pages (every record contains a table) it causes, that tables are not in right order.

Please see the attach document, where explained it:

https://www.dropbox.com/s/piwsqccnyhfvgve/document.pdf?dl=0

Also I am sending InDesign documents:

https://www.dropbox.com/sh/81cgbegek74043n/AAC3nR8yIN1M4ZhnzQcYy_2pa?dl=0

I would be more than thankful if you could help me.

Andrew

[EDIT] Discussion moved to Indesign Script forum with approval from OP by Moderator

TOPICS
Scripting

Views

568

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

correct answers 1 Correct answer

Community Expert , Feb 16, 2017 Feb 16, 2017

Hi Andrew,

I think your problem can be explained.

My assumption based on empiric observation:

The underlying rule how and in what timely order datamerge is building elements with your example is:

1. Calculate the number of pages it needs to store all elements.

2. Begin at the last ( ? ) page from: left to right then from top to bottom.

However, the rule in what order the elements should go on a page could be changed.

See property arrangeBy :

app.documents[0].dataMergeProperties.dataMergePreferences.arra

...

Votes

Translate

Translate
Community Expert ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Hi Andrew,

the easiest way to get the table in the order you want to see is to thread all the frames in the order you do the merge.

Then you would have one single story and:

app.documents[0].pages[0].textFrames[0].parentStory.tables.everyItem().getElements();

would reflect the order you like to see.

How would you effectively thread the text frames?

1. Write a script, that is looking at the geometric bounds of the text frames.

OR:

2. Read out the source text file and check the order of entries and thread accordingly.
( That will only work if all entries are unique. )

From your prepare_dm.indd I can see, that there is no reason why the three text frames could not be just one.

Just three paragraphs in one frame:

prepare_dm.indd-CHANGED.png

Unfortunately you did not provide the merged InDesign document.

Regards,
Uwe

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
Community Expert ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Hm. You also could have asked all this in the Adobe InDesign Scripting forum: InDesign Scripting
If you would agree an admin of the forums could move this thread over there.

Regards,
Uwe

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 ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

Yes, it can be moved to the Adobe InDesign Scripting forum, if the problem is based on a script and there aren't any options to order tables without the script. I have thought that there is a bug or I am doing something wrong, because can't still understand, while data merge makes tables order so messy.

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
Community Expert ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

Hi Andrew,

I think your problem can be explained.

My assumption based on empiric observation:

The underlying rule how and in what timely order datamerge is building elements with your example is:

1. Calculate the number of pages it needs to store all elements.

2. Begin at the last ( ? ) page from: left to right then from top to bottom.

However, the rule in what order the elements should go on a page could be changed.

See property arrangeBy :

app.documents[0].dataMergeProperties.dataMergePreferences.arrangeBy

/*

     value can be:

     ArrangeBy.ROWS_FIRST

     ArrangeBy.COLUMNS_FIRST

*/

I'm not sure about the details of rule #2 , because there were only 2 pages in your result document.

If just one page is needed, all will go as expexted by you.

If more than one page is needed, you'll get your surprise.

If I'm right you could get the right order of tables this way:

var doc = app.documents[0];

var pages = doc.pages.everyItem().getElements();

var tables = [];

// Loop through the pages:

for(var n=0;n<pages.length;n++)

{

    // IDs in creation order on page:

    // per number sort

    var ids = pages.pageItems.everyItem().id.sort(function(a,b){return a-b});

  

    // Loop through the ids-array:

    for(var i=0;i<ids.length;i++)

    {

        var currentItem = doc.pageItems.itemByID(ids).getElements()[0];

      

        // Should be text frame and contains one table.

        // Then add the table to the result array:

        if(currentItem.constructor.name == "TextFrame" && currentItem.tables.length == 1)

        {

            tables[tables.length++] = doc.pageItems.itemByID(ids).tables[0];

        }

    };

};

// Test the result array:

tables[2].rows[0].fillColor = doc.colors.itemByName("Magenta");

Test with more than two pages.

The deeper rule and the trick here:
The higher the id of a page item, the younger the item.

Regards,
Uwe

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
Community Expert ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

I said that datamerge will arrange the objects in creation order this way:

1. Calculate the number of pages it needs to store all elements.

2. Begin at the last ( ? ) page from: left to right then from top to bottom.

I was wrong.

Just did an experiment with your document and provided a data source with 60 entries so that 4 pages will be build from the template.

Then I ran a script that threads all the text frames in creation order according to their ids. Just to illustrate the creation order.

And I moved the contents of the last page to a new layer with color red so that the threading can be seen more obviously.

Here is the results, detail of page 1 and parts of page 2:

Note: The end of the story, the last frame of the story, the last frame datamerge built, is on page 1 and not on page 4.

CreationOrder-by-Document-4.png

Overview pages 1 to 4:

There you can see, that the first frame datamerge is building is on page 2.
Your template is showing the first three text frames on page one in the upper left corner.

CreationOrder-by-Document-3.png

So I conclude that datamerge is:

1. First building all elements of the second page throughout to the last page.

2. And then turns again to the first page to finish the task.

Regards,
Uwe

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
Community Expert ,
Feb 17, 2017 Feb 17, 2017

Copy link to clipboard

Copied

Running my script snippet from reply 5 on the merged (not threaded) result document will find the right table.

Just tested this with:

tables[19].rows[0].fillColor = doc.colors.itemByName("Magenta");

Screenshot of the result where I selected the text frame:

merged-filled-table.row[19]-with-Magenta.png

Regards,
Uwe

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 ,
Feb 18, 2017 Feb 18, 2017

Copy link to clipboard

Copied

Hi Uwe,

Thanks a lot for all your help and patience to solve my problem!

Andrew

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
Community Expert ,
Feb 19, 2017 Feb 19, 2017

Copy link to clipboard

Copied

LATEST

Hi Andrew,

thank you for your feedback.

Glad it's working for you.

Note:

You were lucky, that you had

A. only one text frame with a table per data set and

B. that the stacking order of frames with your template was in geometric order from top to down.

For other more complex templates always make sure that the stacking order of things is in geometric order from top to down or left to right or a mix of both. I mean the geometric order you want to do for identifying elements.

If that's the case you can always:

1. Loop the spreads of your document

2. Loop within that loop the allPageItems.reverse() array of the actual spread

That will show the elements in stacking order per spread and the order data merge is building the elements.

Don't do pageItems.everyItem() on the doc, on the page or the spread. Use allPageItems on the spread.

Before doing the merge always analyze how the stacking order of things is with the template.

And especially analyze the order of nested frames if you are interested in nested items.

Regards,
Uwe

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 ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

Hi Uwe,

Thanks for your advice.

"thread all the frames" - It seems from a variable used in data merge, that frames are in right order. They go 1, 2,...

"three paragraphs in one frame" - Yes, it is true. I didn't realized it, I'm just beginner in InDesign. I have done it, but still tables aren't in right order.

"did not provide the merged InDesign document" - Oh, sorry, I have added it. The file is in the link above.

Shouldn't be tables order one by one in order after data merge? Why if I create only one page, everything works and for more pages it doesn't?

Andrew

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