Copy link to clipboard
Copied
I'm wondering if there's a way to have merged document pages stay in the same layout section as the source file. Right now I've been manually selecting the pages and moving them to their appropriate column. Is there another way to do this so that each record is listed in the same layout as its source?
Hi Dan,
You do something like this, or perhaps this will help get you started:
var doc = app.activeDocument;
for(var i = 0; i < doc.pages.length; i++) {
if(doc.pages.item(i).appliedMaster.name == 'A-Master1') {
// DO SOMETHING
}
else if(doc.pages.item(i).appliedMaster.name == 'B-Master2') {
// DO SOMETHING
}
else {
// DO SOMETHING
}
}
The 'A-Master1' and 'B-Master2' are just what I named the master pages. Replace with the names you have. You may have to use
...Copy link to clipboard
Copied
Hi Daniel,
This might be possible through scripting, hence moving the discussion to InDesign Scripting forum.
Regards,
Srishti
Copy link to clipboard
Copied
I've written up a few solutions that may help:
https://indesignsecrets.com/changing-layouts-during-a-data-merge.php
https://colecandoo.com/2018/04/05/data-merging-to-specific-pages/
Copy link to clipboard
Copied
Thanks Colin! I'm going to try using that first technique for a few other projects. But I'm not sure how it would work with different layouts as well as different page sizes?
Copy link to clipboard
Copied
I was wondering: Since each of the alternate layouts uses a different master, is there a way to select all pages that use a specific master, or color label? That could be another way for me to semi-automate this process.
Copy link to clipboard
Copied
Hi Dan,
You do something like this, or perhaps this will help get you started:
var doc = app.activeDocument;
for(var i = 0; i < doc.pages.length; i++) {
if(doc.pages.item(i).appliedMaster.name == 'A-Master1') {
// DO SOMETHING
}
else if(doc.pages.item(i).appliedMaster.name == 'B-Master2') {
// DO SOMETHING
}
else {
// DO SOMETHING
}
}
The 'A-Master1' and 'B-Master2' are just what I named the master pages. Replace with the names you have. You may have to use a Switch statement if you have a lot of master pages. Hope this helps.
Copy link to clipboard
Copied
Thank you!
I am going through adobe's cs6 scripting tutorial and javascript guides, and will figure out how to // DO SOMETHING
Are there any other recommended resources that are go-tos for indesign scripting?
Copy link to clipboard
Copied
This is a good place to start imo - B E - YouTube a decent amount of indesign scripting basics and such.
Copy link to clipboard
Copied
I've written the following, but I'm stuck when I try to move the current page to a specific section. I'm not sure if I'm using .move or .sections correctly. Where am I going wrong here?
Thanks
//find number of masters in document, each of which corresponds to an alternate layout
var myLayouts = myDoc.masterSpreads.length;
//for each page in the document
for(var i = 0; i < myDoc.pages.length; i++) {
//cycle through all the layouts
var currentSection = myDoc.sections[(i % myLayouts)];
//move current page to the end of current section in cycle
myDoc.pages.item(i).move(LocationOptions.after,currentSection.pages.item(-1));
};
Copy link to clipboard
Copied
Youtuber Daniel Solis also has a unique way of doing something similar, although his technique has the same page size, but different page layouts. Definitely worth watching his video:Card Design Layout Template "Mars Runner" [Patreon Download] - YouTube
Copy link to clipboard
Copied
Interesting, I like the double space to line break GREP trick using max tracking from that vid. I'll have to see if that setup might work better for this the next time I do it.
I found a way to achieve my original goal using the absolute numbering for each page without using a section as a reference. Multiplying with zero indexing threw me off a bit, but eventually got the below to work.
var myDoc = app.activeDocument;
//number of alternate layouts
var myLayouts = myDoc.sections.length;
//for each spread in the document
for(var i = 1 ; i <= myDoc.spreads.length; i++) {
//find position it needs to be moved to by finding its location in grid
var myRow = Math.ceil(i / myLayouts);
var myColumn = (i - 1) % myLayouts + 1;
var myLocation = (myRow * myColumn - 1);
//move it
myDoc.spreads[i - 1].move(LocationOptions.BEFORE,myDoc.spreads[myLocation]);
};
Thanks!