Skip to main content
Known Participant
September 23, 2023
Answered

Indesign script to copy selected items to a new page in another document

  • September 23, 2023
  • 4 replies
  • 1993 views

I have been given a document with 150 pages and I need to copy some elements from some pages into another document, they need to go into separate pages.

Does anybody know if there is a script to do that?

 

In an ideal world it would operate something like like this:

1-select objects in document 1

2-shortcut to run script

3-script copies to document 2

4-and if there are items existing on the page

5-creates a new page and pastes the items.

 

if point 4 not possible, it would just skip and go to step 5.

Any suggestions welcome, thanks.

This topic has been closed for replies.
Correct answer Laubender

Hi @A27300849wzxk ,

if you are working with two documents open, the active document is the one where you selected the items, the other one is the one you like to paste the selected items to, it could go like that:

 

// CopyPasteSelectedItemsToDifferentDoc-v1.jsx

// Copy selected items to the clipboard:
app.copy();

// Switch to the other document, the target document, if only two documents are open:
app.activeDocument = app.documents[1];

// Test if the spread of the target document is empty.
// Add a spread
// Make it the active one
var currentSpread = app.layoutWindows[0].activeSpread;
if( currentSpread.pageItems.length > 0 )
{
	var nextSpread = app.activeDocument.spreads.add();
	app.layoutWindows[0].activeSpread = nextSpread;
};

// Paste the contents of the clipboard to the active spread of the target document:
app.paste();

// To switch back to the source document:
app.activeDocument = app.documents[1];

 

That would work best if both documents are working with none-facing pages where every spread has only one single page and no elements are on the pasteboard. The script would add a new spread at the end of the target document when a selectable item is on the spread.

 

The code will get more complicated if you are using facing pages documents.

Instead of the line app.paste() one could also use app.pasteInPlace() if you want to maintain the relative position of the copied objects according to the source document.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

4 replies

LaubenderCorrect answer
Community Expert
September 23, 2023

Hi @A27300849wzxk ,

if you are working with two documents open, the active document is the one where you selected the items, the other one is the one you like to paste the selected items to, it could go like that:

 

// CopyPasteSelectedItemsToDifferentDoc-v1.jsx

// Copy selected items to the clipboard:
app.copy();

// Switch to the other document, the target document, if only two documents are open:
app.activeDocument = app.documents[1];

// Test if the spread of the target document is empty.
// Add a spread
// Make it the active one
var currentSpread = app.layoutWindows[0].activeSpread;
if( currentSpread.pageItems.length > 0 )
{
	var nextSpread = app.activeDocument.spreads.add();
	app.layoutWindows[0].activeSpread = nextSpread;
};

// Paste the contents of the clipboard to the active spread of the target document:
app.paste();

// To switch back to the source document:
app.activeDocument = app.documents[1];

 

That would work best if both documents are working with none-facing pages where every spread has only one single page and no elements are on the pasteboard. The script would add a new spread at the end of the target document when a selectable item is on the spread.

 

The code will get more complicated if you are using facing pages documents.

Instead of the line app.paste() one could also use app.pasteInPlace() if you want to maintain the relative position of the copied objects according to the source document.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Known Participant
September 23, 2023

Brilliant! Thanks Uwe, this is exactly what I was after. Works perfect, and it is so quick. It will save me bags of time.

Thank you for your solution!

 

Community Expert
September 23, 2023

@A27300849wzxk said: "… Thanks for your reply Uwe, all items to be copied must be selected manually, depending on the page might be text boxes, picture boxes, rectangles, etc. So there is no "standard" items."

 

Hm. One rule could also be "copy all items from that page".

Apart from that a script can actually work on selected items.

It can use the menu commands that currently are available ( not grayed out ) or it can use other methods.

 

Do you copy from a facing pages document to another facing pages document?

Or do you copy from a document with one page per spread to another document with one page per spread?

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

Known Participant
September 23, 2023

Do you copy from a facing pages document to another facing pages document?

Or do you copy from a document with one page per spread to another document with one page per spread?

Thanks, Uwe, the documents I copy from are spreads and single pages (and different sizes) and the document I copy to is setup as single pages.

Community Expert
September 23, 2023

Hi @A27300849wzxk ,

how do you know what items must be copied over?

If there is an easy algorithm for this, a script could duplicate all of the items in one run.

 

An algorithm, perhaps like copy all items on a given layer in a particular range of pages.

Or, copy all text frames. Or, copy all items with fill color "blabalaba". Something like that…

Or a combination of the above. A rule or a set of rules what is to copy over.

 

On the other hand, it takes a lot more time to formulate the algorithm, to write and finally to test a script than to do it the "manual" way. At least most of the time.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Robert at ID-Tasker
Brainiac
September 23, 2023

I'm pretty sure OP needs to automate the copy&paste part only - copy selection to new document -> with checking if page is empty -> and create new page if not empty -> then paste -> and go back to first document.

 

Robert at ID-Tasker
Brainiac
September 23, 2023

You don't really need script for that...

 

  1. select elements in DOC-1
  2. CTRL+C
  3. CTRL+TAB - switch to DOC-2
  4. if you see something on a page - add new page (*)
  5. CTRL+V
  6. CTRL+TAB - switch to DOC-1
  7. SHIFT+PageDown - go to next page
  8. goto step 1.

 

(*) - you can set a shortcut for adding new PAGE:

I've assigned "Numpad 9"

 

It would be much easier if you were working on a PC - you could use my ID-Tasker - even free version could do this...

 

Known Participant
September 23, 2023

Thank you very much for your reply Robert, I have been doing something similar to your suggestion with previous documents. That is, manually copying and pasting between documents.

I am trying to reduce the amount of copy/paste and jumping between documents, hence thinking that there might be a script that does something similar and that I could assign a shortcut.

The main issue is that first I have to select some, but not all the items in the page of Doc 1, then copy to a new page in  Doc 2...

Unfortunatelly cannot try ID-Tasker, as I am on a Mac... But thaks for the suggestion!