Copy link to clipboard
Copied
Hello,
I'm fairly new to InDesign and would appreciate some assistance. I've been attempting to write a script for the past few days.
Let's say I have 5 unsaved documents open. What I'd like to achieve is to select a certain number of documents (for example, 2 documents, which may have varying numbers of pages but are of the same size), and merge them into one document. This merged document can either replace one of the original two or be created as a new document. (Additional information: the document size is landscape 297 x 210 mm with 5 mm margins and no facing pages).
However, the documents that were merged would need to be closed without being saved.
If my expectations are too high, I apologize.
Thank you for your assistance!
Merge files by Michael Zaichenko
Mass combine a bunch of indd files into one by Simon Wiscombe
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. Set the destination document as the active document.
Copy link to clipboard
Copied
What is the script you're attempting?
Copy link to clipboard
Copied
Merge files by Michael Zaichenko
Mass combine a bunch of indd files into one by Simon Wiscombe
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. Set the destination document as the active document.
Copy link to clipboard
Copied
Thank you @Kasyan Servetsky this helped me a lot.
I helped myself with chatGPT and managed to get the desired result. Otherwise, in some cases it folds the pages incorrectly. Across the width instead of down.
But it doesn't affect my usage.
I am attaching the script if anyone needs it. (comments are only in Slovenian).
When the script is started, a window with all open documents opens. The desired ones are selected, and then they are combined into one document.
However, all downloaded documents are closed without being saved.
#target indesign
// Preveri, če so odprti dokumenti
if (app.documents.length == 0) {
alert("Ni odprtih dokumentov.");
exit(0);
}
// Ustvari dialogovno okno za izbiro dokumentov
var dialog = new Window("dialog", "Izberite dokumente za združitev");
// Panel za izbiro dokumentov z kvadratki
var docPanel = dialog.add("panel", undefined, "Dokumenti:");
docPanel.alignChildren = "left";
var checkboxes = [];
for (var i = 0; i < app.documents.length; i++) {
checkboxes.push(docPanel.add("checkbox", undefined, app.documents[i].name));
}
// Gumbi za dialog
var buttons = dialog.add("group");
buttons.alignment = "center";
buttons.add("button", undefined, "V redu", {name: "ok"});
buttons.add("button", undefined, "Prekliči", {name: "cancel"});
// Prikaži dialog in preveri izbiro
if (dialog.show() == 1) { // V redu
var selectedDocuments = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].value) {
selectedDocuments.push(app.documents.itemByName(checkboxes[i].text));
}
}
// Preveri, če je bil izbran vsaj en dokument
if (selectedDocuments.length < 1) {
alert("Izberite vsaj en dokument.");
exit(0);
}
// Izračunaj skupno število strani za napredek
var totalPages = 0;
for (var i = 0; i < selectedDocuments.length; i++) {
if (selectedDocuments[i] != selectedDocuments[0]) { // Preskoči ciljni dokument
totalPages += selectedDocuments[i].pages.length;
}
}
// Ustvari okno za napredek
var progressWin = new Window('palette', 'Napredek združevanja');
var progressBar = progressWin.add('progressbar', undefined, 0, totalPages);
// Nastavi velikost okna za napredek
progressWin.preferredSize.width = 300; // Nastavi prednostno širino
progressBar.preferredSize.width = 280; // Nastavi prednostno širino za napredovalno vrstico
// Center okna na zaslonu
progressWin.center();
// Prikaži okno za napredek
progressWin.show();
var pagesDone = 0; // Za sledenje napredka
// Nastavi ciljni dokument kot prvi izbrani dokument
var destination_doc = selectedDocuments[0];
// Nastavi ciljni dokument na enostranske razpredelnice
destination_doc.documentPreferences.facingPages = false;
// Preglej izbrane dokumente za združitev
for (var i = 1; i < selectedDocuments.length; i++) { // Začni z 1, ker je 0 ciljni dokument
var source_doc = selectedDocuments[i];
// Preglej vse strani v trenutnem dokumentu
for (var j = 0; j < source_doc.pages.length; j++) {
var sourcePage = source_doc.pages.item(j);
// Prekini povezavo z master stranmi, če je potrebno
var masterItems = sourcePage.masterPageItems;
if (masterItems.length > 0) {
for (var k = 0; k < masterItems.length; k++) {
masterItems[k].override(sourcePage);
}
}
// Odstrani uporabljeno master stran
sourcePage.appliedMaster = null;
// Preveri, če je število strani v zadnji razpredelnici večje ali enako 10
var lastSpread = destination_doc.spreads.lastItem();
if (lastSpread.pages.length >= 10) {
// Dodaj novo stran na koncu, kar bo po potrebi ustvarilo novo razpredelnico
destination_doc.pages.add(LocationOptions.AT_END);
}
// Dupliciraj stran v izvornem dokumentu in jo premakni v ciljni dokument
sourcePage.duplicate(LocationOptions.AT_END, destination_doc.pages.item(-1));
// Posodobi napredek
pagesDone++;
progressBar.value = pagesDone;
}
// Zapri izvorni dokument brez shranjevanja
source_doc.close(SaveOptions.NO);
}
// Zapri okno za napredek
progressWin.close();
} else { // Prekliči
exit(0);
}
Copy link to clipboard
Copied
Hello!
This does combine files, but it loses the text threads in the files after the first one. Since I'm working in book publishing, my need is to, for example, combinge 10 individual multi-page lessons into a single file. (Not using the ID Book feature, but actually having one ID file so I can combine master pages and bulk edit styles in 1 file instead of 10).
The Move Pages.... command works well manually and does exactly what I am trying to automate, but all of the scripts I've seen break the text threads across pages.
I would welcome any ideas you have. I am not a programmer, but I love using time-saving scripts that also save my hands and wrists from repetitive stress injuries!
-Carol
Copy link to clipboard
Copied
I have a tool that can handle this with ease - and can do A LOT more - but isn't free and Windows only...
Copy link to clipboard
Copied
@bracewell4213 said:
"… This does combine files, but it loses the text threads in the files after the first one. "
Hi @bracewell4213 ,
I think the trick is to use itemByRange() for the pages object in combination with the duplicate() command.
Example:
Have two documents open. The active one is the source document, the second one is the target document. Let's say we want to "move" ( or copy ) the second and the third page of our source document at the end of the target document without losing the text thread accross spread 1 and spread 2:
The code I used is this:
/*
TEST 1:
Use pages.itemByRange()
with duplicate()
*/
var source = app.documents[0];
var target = app.documents[1];
var fromIndex = 1; // second page in source
var toIndex = 2; // third page in source
var targetPage = target.pages[-1]; // Last page of target document
source.pages.itemByRange( fromIndex , toIndex ).duplicate( LocationOptions.AFTER , targetPage );
The result where the text frames in the target document are still threaded:
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Interesting... A few weeks ago there was a thread about moving pages between documents - and threading between spreads was definitely broken?
Copy link to clipboard
Copied
@Robert at ID-Tasker said: "Interesting... A few weeks ago there was a thread about moving pages between documents - and threading between spreads was definitely broken?"
After doing some tests with the current release version of InDesign 2024 v 19.5.4:
To get all pages duplicated that are defined in itemByRange() to the target document it could be important that page orientation is the same in source and target documents. A mix of page sizes and orientation could get you strange results.
FWIW: In all my experiments I never had a broken text thread when I used the combination of itemByRange() and duplicate() with the pages object from the source document when the target page was the last one in the target document.
Well, I have to leave this thread for now.
Maybe I have time the next days to revisit.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi @Robert at ID-Tasker ,
I tested with the current prerelease version of InDesign 2025. Will do more tests with the release versions 2024 and 2025. I used pages.itemByRange() and not spreads.itemByRange() like you did in one post. Could make a difference perhaps. And in my tests I added the pages always after the last page of the target document.
Note, that there also was a thread from 2016 where itemByRange() in combination with move() did not work as expected. Cannot find the thread in the forum; a lot is missing and is lost because of the restructuring of the forums in 2019.
Also: Could well be that something changed with InDesign in the course of a few years.
What definitely is breaking the threads is this script:
Merge files
Author: Michael Zaichenko
MergeFiles-2016.jsxbin
http://kasyan.ho.ua/indesign/all/merge_files.html
Regards,
Uwe Laubender
( Adobe Community Expert )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now