Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
//DESCRIPTION: Merge the two open documentsDave
(function() {
if (app.documents.length != 2) {
alert("Please open two InDesign documents and try again."); return;
} else {
var doc1 = app.documents[0];
var doc2 = app.documents[1];
if (checkPageSizes(doc1, doc2)) {
// docs have same page sizes
var pHt = doc1.documentPreferences.pageHeight;
var pWd = doc1.documentPreferences.pageWidth;
if (!doc1.saved || !doc2.saved) {
if (!confirm("Both documents will be saved before closing. Continue?")) {
return;
}
}
var doc1Lim = doc1.pages.length;
var doc2Lim = doc2.pages.length;
var file1 = doc1.fullName;
var file2 = doc2.fullName;
doc2.close(SaveOptions.yes);
doc1.close(SaveOptions.yes);
app.documentPreferences.facingPages = false;
newDoc = app.documents.add();
newDoc.documentPreferences.properties = {
pagesPerDocument:Math.max(doc1Lim, doc2Lim)*2,
pageHeight:pHt,
pageWidth:pWd
}
app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.cropContent;
var j = 0;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
while (true) {
app.importedPageAttributes.pageNumber = j + 1;
if (doc1Lim > j) {
newDoc.pages[j * 2].place(file1);
}
app.importedPageAttributes.pageNumber = j + 1;
if (doc2Lim > j) {
newDoc.pages[(j * 2) + 1].place(file2);
}
j++;
if (j > Math.max(doc1Lim,doc2Lim)) break;
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
} else {
alert("Two documents must have the same page size"); return;
}
}
function checkPageSizes(doc1, doc2) {
var d1ht = doc1.documentPreferences.pageHeight;
var d1wd = doc1.documentPreferences.pageWidth;
var d2ht = doc2.documentPreferences.pageHeight;
var d2wd = doc2.documentPreferences.pageWidth;
if (d1ht != d2ht) return false;
if (d1wd != d2wd) return false;
return true;
}
}())
Copy link to clipboard
Copied
tried this in CS5, on a mac.
froze the program, fyi.
edit: although it did freeze up, it was working in and generated about 1/3 of what i needed, i guess i'll have to let it run a while longer for the size of the file i'll be generating.
Copy link to clipboard
Copied
I get this error:
Copy link to clipboard
Copied
Some coying played a trick on you. Replace this line:
if (doc1Lim > j) {
with this:
if (doc1Lim > j) {
Peter
Copy link to clipboard
Copied
Thanks, pkahrel. I didn't think of comparing the pasted text to the above original. I.ve written applescript, not so much Java.
Copy link to clipboard
Copied
pkahrel,
I fixed the code as suggested above. I checked every line against the original.
I open two 20 pg Indesign docs, run the script and now get this error.
It closes the Doc A and Doc B, creates a new Untitled doc that is correctly 40 pages.
I wish could step through the script and see the results of each variable change to track down the problem.
BTW, the Doc A.indd does exist on the desktop as well as Doc B. innd.
I thought maybe it was having trouble since both docs are using Master page A, so in doc B, I changed its master to "B".
I also told each 20 pages to Override Master page items.
Still no luck. Any help is appreciated. Using in Indesign CC 2015.
Copy link to clipboard
Copied
Sorry, I don't know that script at all, I just spotted that error.
I can't tell what's causing the problem at line 37.
> I wish could step through the script and see the results of each variable change to track down the problem.
You can:
1. Open the script in the ESTK (right-click it in the Script panel, then choose Edit Script).
2. Go to the Debug menu and select Step Over. This starts running the script and pauses at every line. In the console you can type a value to inspect it, and the Data browser shows details of the contents of various variables.
3. To go to the next line, select Step Over again.
The ESTK has its quirks (to put it mildly) but it's the only debugging tool for JavaScripts, and it's workable enough. You can read up on it in the JavaScripts Tools Guide (see the ESTK's Help menu), chapter 2.
Peter
Copy link to clipboard
Copied
Tried that. Stepping through, the ESTK does not work within Indesign. Even though you might have the 2 docs opened, while stepping, it doesn't know Indesign has the docs opened. It errors saying, "open two documents". Real frustrating.
Copy link to clipboard
Copied
Bit of an old thread, I got the script to work that Dave_Saunders posted above, it's great. I just wanted to know if it's possible to include the bleed from the original two documents through to the final interwoven document? I have a work around that involves changing the document sizes to include the bleed, but it would be great if the script could do this.
Thanks
Copy link to clipboard
Copied
There is a line in the code above from Dave Saunders:
app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.cropContent;
Can it be changed to include the bleed instead of crop only?
Copy link to clipboard
Copied
Replace cropContent with cropBleed.
Peter
Copy link to clipboard
Copied
Thanks pkahrel.
I tested it. The art comes in with bleed but places at 0,0 instead of -.125", -.125" coordinates offsetting the page content. Not sure where to make the script offset. It doesn't have to be variable, we always use .125" bleed.
Copy link to clipboard
Copied
Yeah it would be great if the placed page content was placed at the bleed bounds rather than page bounds.
I've tweaked the script so that it takes the bleed from 'Doc1' and checks that 'Doc2' has the same size bleed. I've also tweaked it so that the bleed amount is added into the newly created document. However i'm just not sure how to specify the position of the place page content.
My tweaked script is here.
(function() {
if (app.documents.length != 2) {
alert("Please open two InDesign documents and try again."); return;
} else {
var doc1 = app.documents[0];
var doc2 = app.documents[1];
if (checkPageSizes(doc1, doc2)) {
// docs have same page sizes
var pHt = doc1.documentPreferences.pageHeight;
var pWd = doc1.documentPreferences.pageWidth;
var myDocBleed = doc1.documentPreferences.documentBleedTopOffset;
if (!doc1.saved || !doc2.saved) {
if (!confirm("Both documents will be saved before closing. Continue?")) {
return;
}
}
var doc1Lim = doc1.pages.length;
var doc2Lim = doc2.pages.length;
var file1 = doc1.fullName;
var file2 = doc2.fullName;
doc2.close(SaveOptions.yes);
doc1.close(SaveOptions.yes);
app.documentPreferences.facingPages = false;
newDoc = app.documents.add();
newDoc.documentPreferences.documentBleedTopOffset = myDocBleed;
newDoc.documentPreferences.documentBleedUniformSize = true;
newDoc.documentPreferences.properties = {
pagesPerDocument:Math.max(doc1Lim, doc2Lim)*2,
pageHeight:pHt,
pageWidth:pWd
}
app.importedPageAttributes.importedPageCrop = ImportedPageCropOptions.cropBleed;
var j = 0;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
while (true) {
app.importedPageAttributes.pageNumber = j + 1;
if (doc1Lim > j) {
newDoc.pages[j * 2].place(file1);
}
app.importedPageAttributes.pageNumber = j + 1;
if (doc2Lim > j) {
newDoc.pages[(j * 2) + 1].place(file2);
}
j++;
if (j > Math.max(doc1Lim,doc2Lim)) break;
}
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
} else {
alert("The two documents must have the same page size and bleed amount. Change these and re-run the script."); return;
}
}
function checkPageSizes(doc1, doc2) {
var d1ht = doc1.documentPreferences.pageHeight;
var d1wd = doc1.documentPreferences.pageWidth;
var d1bleed = doc1.documentPreferences.documentBleedTopOffset;
var d2ht = doc2.documentPreferences.pageHeight;
var d2wd = doc2.documentPreferences.pageWidth;
var d2bleed = doc2.documentPreferences.documentBleedTopOffset;
if (d1ht != d2ht) return false;
if (d1wd != d2wd) return false;
if (d1bleed != d2bleed) return false;
return true;
}
}())
Copy link to clipboard
Copied
I've been searching for something like this for ages. This is great to finally find a script that merges 2 InDesign files on alternate pages (writing this to help with SEO).
Thanks so much again!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now