Members Only

How Data Merge and Scripting Can Save the Day

Learn how InDesign’s capabilities turned a fragile, deadline-driven layout into one that reflows itself.

This article appears in Issue 61 of CreativePro Magazine.

Most people think of InDesign’s data merge as useful for inserting content into one field in an otherwise static project—certificates and name badges, to name two classic examples. 

But Data Merge can handle a lot more than that if you’re willing to push it and, flexing a newfound understanding of scripts, I ended up using it to solve a problem that wouldn’t stand still.

A Data Merge Challenge

I work for Walsworth, which prints school yearbooks (among many other publications), and every other year we produce Possibilities, a book full of examples and tips to celebrate standout work from our yearbook customers.

The book (Figure 1) features hundreds of examples from high schools and middle schools that either carried a strong design from cover to cover or produced something innovative in print. The book covers themes and how schools carried them through their books, cover design, spread design, and photography. It also shares projects that used print in ways other schools might not know are possible. 

Figure 1. Our 412-page Possibilities book (A), published every other year, celebrates the good work of our company’s yearbook publishing clients. The book has a holographic silver acrylic cover, silver acrylic endsheets, multiple gatefolds, a tip-in booklet (a smaller piece bound into the book), and UV coating on the interior pages. With that much content, manual layout eats time fast. So much of the book is data driven, like this spread (B), that we realized the possibilities for automating its production.

Its layout is surprisingly consistent. When I sat down with the project manager and designer to map out the whole process, we found that most spreads follow the same format: a school name, some details, and a set of images in the same positions, page after page.

The data lived in a CSV file that was clean enough to work with, making most of the book a strong fit for data merge. We could pull information and images into the layout quickly and let the designer handle adjustments from there.

One problem immediately emerged: By itself, Data Merge could automate the initial layout of the pages, but if we would need to add or remove an entry from the sequence, the designer would have to insert a new profile into the flow and shuffle the position of every remaining group by hand on dozens of pages. 

We could re-run the whole merge each time to rebuild the pages with the profiles in the updated sequence, but that would not be ideal. I wanted a way to run an initial merge once and keep editing from there. 

InDesign would need a little assistance. I created a script to take each of those groups and paste it as an anchored object into a document’s primary text frame, creating one story with all the yearbook projects. 

The script uses script labels to treat grouped data merge content  as it would a single character in a flow of text.

Now, to change the order or add or delete one of these yearbook examples, a designer can cut or paste a group. The layout reflows!

How to Build It

Here are the steps I used to create the project. This isn’t a full Data Merge tutorial; CreativePro already has plenty of coverage on the basics, including the Data Merge Super Guide (a free download for members). 

Create your target document

Set up and apply separate object styles for your variable image frame and for your variable text frame (Figure 2).

Figure 2. The Object Styles panel, showing the image frame, text frame, and group styles used in this workflow

Create a third object style for the variable group. Caution: The group object style overrides the individual styles underneath it. Turn off any settings that would conflict with your image or text frame styles. Fill is the most common culprit. 

Set up character and paragraph styles for your text. Even a stripped-down set with default fonts works. Tip: The script preserves whatever formatting you assign, so styling here pays off later when you need to make document-wide adjustments. 

Create a fresh parent page for the creation of the grouped text/image and apply it to the first page of your document. 

On this first document page (not the parent), group your text frame and image, apply your group object style, and assign a script label (Window > Utilities > Script Label) to the group.  (The script, by default, expects the label to be named “record.”)

Create your merged document with running text

Run your data merge to create your merged INDD file.

On your merged document with all your groups in sequence, run my FlowGroupedObjects script. In the dialog box, choose the parent page that holds your destination text frames, and confirm or edit your record label and container label. The two labels work together to tell the script what to gather and where to send it. (Figure 3). 

Figure 3. The Flow Grouped Records dialog box

The script creates a two-page spread for the project (to avoid the scrambled-flow issue). It then adds every labeled record from the merged-page document into the primary text frame of the book document, in order. You can choose to delete the leftover blank merge pages.

If you’re flowing into a single page instead of a spread, you can skip page creation entirely. Just make sure your container label is set, and tell the script not to create pages.

Caution: If records come out of order across a spread, you almost certainly created the destination pages separately instead of together as a full spread. The FlowGroupedObjects script handles this automatically, but if you’re customizing the process by hand, build both pages of the spread at once, and confirm that the primary text frames are linked across the spread before running your merge.

Tip: Create an object style for your destination document’s primary text frame and apply it before running the script. If you need to make changes like switching a three-column layout to two columns, you can edit the style once (Figures 4 and 5).

Figure 4. By applying an object style to the destination text frame, you can automatically modify how your merged data flows and reflows through your book layout. Here, the object style applied to the primary text frame defines the frame as three columns.
Figure 5. When you modify the same object style to two columns, every linked frame updates automatically.
Search Before You Build

If you’d like to build your own Data Merge script (or any script), search for an existing script before asking your AI agent to write you a new one. Chances are that someone has already solved your problem. If you end up using their script, remember to tip your scriptwriters.

Case in point: After I built FlowGrouped­Objects, I discovered that it closely mirrors elements of Loic Aigon’s InlineMerge script, which David Blatner discussed in a CreativePro post.

That’s not really a coincidence. If you understand how the program’s pieces fit together, it makes sense that two people would land on a similar approach independently. I’m not sure InlineMerge accounts for the primary text frame and Smart Text Reflow setup I built around, but my script almost certainly exists because scripts like InlineMerge came before it.

Lessons Learned

Though my concept seemed like a tidy solution, the process of creating the script wasn’t so clean. I discovered that when a primary text frame spans a spread, you need to create the two pages together as a full spread from the start. Add them one at a time—even onto a parent page built for it—and the connection between the frames breaks. 

Once I understood what was happening and why, I could design around that behavior instead of fighting it. And that turned out to be one of the more useful lessons in this whole project.

Bookmark
Please login to bookmark Close

Not a member yet?

Get unlimited access to articles and member-only resources with a CreativePro membership.

Become a Member

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading comments...