Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Moving multiple pages via script

Explorer ,
Feb 08, 2022 Feb 08, 2022

Is it possible to move mutliple pages in InDesign scripting with a single move call or do you need to move one page at a time?

TOPICS
Scripting
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 08, 2022 Feb 08, 2022

It's hard to say if it's one page at a time. The move() method belongs to Page and not Pages, so you could infer that the API moves one page at a time. But here's a simple example of moving some pages, and it is basically one call for multiple pages if you do it this way.

- Mark

var doc = app.activeDocument;
var allPages = doc.pages;
var myPages = allPages.itemByRange(4, 7);
myPages.move(LocationOptions.AT_BEGINNING);
Translate
Community Expert ,
Feb 08, 2022 Feb 08, 2022
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2022 Feb 08, 2022

It's hard to say if it's one page at a time. The move() method belongs to Page and not Pages, so you could infer that the API moves one page at a time. But here's a simple example of moving some pages, and it is basically one call for multiple pages if you do it this way.

- Mark

var doc = app.activeDocument;
var allPages = doc.pages;
var myPages = allPages.itemByRange(4, 7);
myPages.move(LocationOptions.AT_BEGINNING);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 08, 2022 Feb 08, 2022

Interesting. I will need to give that a try! Thanks for sharing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 08, 2022 Feb 08, 2022

Mark, 

 

It worked like a charm! Thank you so much for answering my question and helping out.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2022 Feb 08, 2022

Good to hear! 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2022 Feb 08, 2022

Hi Mark,

Good one, I missed that. However, correct me if I am wrong this will always move a contigous set of pages to a common destination, it won't cater to use cases of moving say single pages to different locations.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2022 Feb 08, 2022

You are exactly right. And I can't see how to get a reference to multiple non-contiguous pages either.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 16, 2025 May 16, 2025

Hi Mark,

Sorry to open an old thread. I'm surprised how hard it is to find a script that basically does Move Pages to another document. I have 10 lessons per book, 10 separate ID files,  and need to combine them and I'm doing it manually. 

Do you happen to have a script you can share that would facilitate this? (I have used scripts but know nothing about writing them).  I know I have to have the source file open to move to the target file manually. In my fantasy, I would have the target file open and a script would ask me to choose the source file(s). Or just combine all. But anything would be better than what I'm doing now.

MultiFileImporter places an image of a page, not threaded pages.
MergeFiles-2016 script doesn't seem to handle text threads.

Thanks for any advice!

-Carol

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2025 May 16, 2025

I don't know what Mark has up his sleeve, but I have this little snippet of code that I modified, years ago, based off an ancient Marijan Tompa post. I might be able to modify it to suit your purposes, as I wrote (er, stole) it at a time where I really didn't have the skill to modify it easily. The way it's currently set up is that it copies all of the pages from the active document into the next open document, after the last page. It doesn't move the pages, it duplicates them, so it's more of a "copy pages" script than a "move pages" script. If that doesn't work for you, I think all you'd have to do is change ".duplicate" to ".move". 

var pageSource = app.documents[0]; 
pageSource.pages.everyItem().duplicate(LocationOptions.AFTER, app.documents[1].pages.item(-1));

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 16, 2025 May 16, 2025

Hi Joel,

The key is it has to maintain the text threads or it is of no use, unfortunately. It seems other scripters have struggled with this. The existing command  "Move Pages" to another document has no impact on the source file if you uncheck Delete pages, but that doesn't really matter, since I would just close the source file without saving. 
If you think just changing to Move would work with the existing parameters, I'm happy to try it, but Move is a different command and may have different variables.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2025 May 16, 2025

Well, the .duplicate method moves all pages intact with threading intact... assuming that both documents are single-page documents in Engilsh. I can make it mess up page order if I e.g. move a spine-right Arabic document with spreads into a normal spine-left English document with spreads. But if you're not mixing languages or directions, then this script will automatically copy all of your source document apges, threading intact, into your target document. 

 

(I played around with it a bit; it turns out that you can't .move all pages from one doc to another, because that means your source doc would have zero pages, which is impossible in InDesign.) 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 16, 2025 May 16, 2025

My documents are all facing pages and currently I move chapter 2 into chapter 1, then move chapter 3 into #1, then chapter 4, etc.  I've attached a screenshot. I'm applying the new master pages and automating RH after each import.

Seems it's worth trying the script, as I have 9 more volumes to do. They take me about an hour a volume currently.

It seems so funny to me that after decades of people using InDesign for book publishing, this hasn't been more in demand!

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2025 May 16, 2025

I think that, when people need to combine individual InDesign documents into larger documents, we typically use Book files. That's what I've done when I was in your shoes in the past, because I'd have a few hundred single-page forms and instructions, and I'd need to combine them in a variety of different ways. That might be even faster for you than using this script, but there might be workflow reasons why you're not using Book files? 

 

It looks like this little script works just fine when both source and target are set up for facing pages with spine left. It's only when source and target are different w/r/t spine orientation and single/facing pages that Problems Crop Up, it looks like. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2025 May 16, 2025

@bracewell4213 Hi Carol, for another thread I've written a script that combines documents. It doesn't work quite how you ask, but I'd like you to try it out and see if it will work as is.

 

To use the latest version, first download it from my github repo or you can download just the script directly. It requires you to add all your documents to a book (temporary is fine) This provides a good way to control the ordering of the documents. The run the script and you will see the UI:

combine-documents-ui-1.pngDo you think that script might help in your case?

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 19, 2025 May 19, 2025
LATEST

Hi Mark,

Yes, this is exactly what I'm looking for, and works great because the docs are already in a Book, so I just remove the covers and FM and initiate the script. It graciously allows me to press Skip for the missing fonts dialog for each file it opens, then chugs away and eventually presents a file with the book name + "combined" (summarizing what you already know for future forum searchers). 

 

Fortunately, the previous designer had the master pages all with the same name. While that makes a bit of a mess on the chapter opening pages in the combined file, it is in fact what I need because I am rehabbing the masters with automated running heads. I think many designers make multiple files from the same template is because they want to swap out the chapter information on the master page running heads. (Or they think their computer cannot handle a large file?) I prefer to combine all to a single file and use my own tricks for pulling various data onto the running heads on the fly.

 

The Book panel does have a lot of powerful sync features, but I've gotten burned in the past, perhaps due to my own ignorance or file setup requirements I don't fully understand. (I inherit lots of large projects that I can never fully investigate while on deadline.) So rather than sync Book files, I prefer to do global style changes and pagination/master changes in a single document, skipping the Book panel.

 

I really appreciate how elegant this script is and it's yet another thing that I would love for Adobe to add to the functionality of the Book panel, should Adobe ever return its attention to the book publishing community and all the things not updated in InDesign in the last 20 years. 🙂

 

Thanks so much to scripters like yourself that continue to advance this software. I'm happy to pay for scripts and extensions that are so useful. (Mark, I will also check out your Copy Things script on your github.)

 

-Carol

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines