Created
June 25, 2015 17:03
-
-
Save senki/7e06e8adeb390eca8ece to your computer and use it in GitHub Desktop.
Mass combine a bunch of indd files into one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DESCRIPTION: Mass combine a bunch of indd files into one. | |
// 6 July 2013 | |
// edited by senki on 2015-06-21 | |
// Added ability to move all pages not just first | |
// INSTRUCTIONS | |
// Put all the files you want to combine into one document in a folder, named in the order | |
// you want them to appear in the book (e.g. "001.indd", "002.indd", etc. or something) so | |
// they appear correctly when sorted by name in finder/explorer. | |
#target indesign | |
// set the destination document as the active document. | |
var destination_doc = app.activeDocument; | |
// select the source folder | |
var sourceFolder = Folder.selectDialog("Select a folder with source InDesign files."); | |
// if we're not in the source folder, stop running the script. | |
if ( !sourceFolder ) { | |
exit(0); | |
} | |
// set file list and run through each file. Sorting them alphanumerically. | |
var fileList = sourceFolder.getFiles(); | |
fileList.sort(); | |
// the original interaction and warning settings of the application | |
var oldInteractionPrefs = app.scriptPreferences.userInteractionLevel; | |
// prevent interaction and warnings from interrupting script | |
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; | |
// run through each file | |
for ( var i = 0; i < fileList.length; i++ ) { | |
var source_file = fileList[i]; | |
// making sure it's an indesign file... | |
if ( source_file instanceof File && source_file.name.match(/\.indd$/i)) { | |
app.open(source_file); | |
var source_doc = app.open(source_file); | |
// walk the document's pages | |
for (var j = 0; j < source_doc.pages.length; j++) { | |
var sourcePages = source_doc.pages.item(j); | |
// break the master page items so they can be moved onto the new document. | |
var masterItems = sourcePages.masterPageItems; | |
if ( masterItems.length > 0 ) { | |
for ( var k=0; k<masterItems.length; k++ ) { | |
masterItems[k].override(sourcePages); | |
} | |
} | |
// removing the applied master (this can mess up some files if not done) | |
sourcePages.appliedMaster=null; | |
// duplicating it in the original file (due to errors) and them moving it to | |
// the destination document. | |
sourcePages.duplicate(LocationOptions.AFTER, source_doc.pages.item(j)); | |
sourcePages.move(LocationOptions.AFTER, destination_doc.pages.item(-1)); | |
// closes the file that was opened without saving (to avoid memory problems) | |
} | |
app.activeDocument.close(SaveOptions.NO); | |
} | |
} | |
// reset interactions to original settings | |
app.scriptPreferences.userInteractionLevel = oldInteractionPrefs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment