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

Copy layer content between InDesign files

Community Beginner ,
Jul 11, 2011 Jul 11, 2011

Copy link to clipboard

Copied

Hello,

I'm trying copy layer content between 2 files, the sources file is a Spanish version of a training manual and the target is an English version. Essentially making a single multiple language file out of two single language documents.

I'm not well-versed in scripting.

Thanks

Views

31.0K

Translate

Translate

Report

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 ,
Jul 07, 2017 Jul 07, 2017

Copy link to clipboard

Copied

Hi all,

I just figure it out that this script can provide unexpected results.

If one of your layers contents different objects with a certain order > the script will change the order of each elements.

app.documents[1].layers.add ({name: "Copied Layer"}); 

var sourceLayer = app.documents[0].layers.itemByName("Copy Me"); 

var destLayer = app.documents[1].layers[0]; 

sourceLayer.pageItems.everyItem().duplicate(destLayer); 

to correct this behavior, I suggest that:

var all_frames = source_layers[i].pageItems.everyItem().getElements();

var count_frames = all_frames.length;

for (var j = count_frames - 1; j >= 0; j--) {

   if (all_frames[j].constructor.name === 'TextFrame' && my.mainView.items_textframes.value) {

   all_frames[j].duplicate(current_layer);

  }

   if (all_frames[j].constructor.name === 'Graphic' && my.mainView.items_graphics.value) {

   all_frames[j].duplicate(current_layer);

  }

   if (all_frames[j].constructor.name !== 'TextFrame' && all_frames[j].constructor.name !== 'Graphic' && my.mainView.items_others.value) {

   all_frames[j].duplicate(current_layer);

  }

}

I hope this will be helpful for somebody.

Best,

Bastien

Votes

Translate

Translate

Report

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 ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

Hi Bastien,

I think, you'd better do a new thread in the InDesign Scripting forum to discuss issues like that and go back here when found a solid solution. E.g. I do not understand your if statements where you are using the object my that is not defined in the code.

FWIW: For automatically threading text frames you would better stick with the script layer-cloner-1.3.jsxbin that is linked to in reply 25:

Re: Copy layer content between InDesign files

But layer-cloner-1.3.jsxbin comes with some issues:

It will not stack items in the right order, has no error handling of exceptional situations and no global undo.

It is saved as jsxbin format so one cannot see into the code to do anything for fixing issues.

Regards,
Uwe

Votes

Translate

Translate

Report

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 ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

Hi,

Thank you for your message. I already post a solid solution:
If you want to keep the correct order of each element during the copy / paste > you have to loop the array from the end:

var all_frames = source_layers.pageItems.everyItem().getElements(); 

 

var count_frames = all_frames.length; 

 

for (var j = count_frames - 1; j >= 0; j--) { 

 

 

   if (all_frames.constructor.name === 'TextFrame') { 

 

   all_frames.duplicate(current_layer); 

 

  } 

 

   if (all_frames.constructor.name === 'Graphic') { 

 

   all_frames.duplicate(current_layer); 

 

  } 

 

   if (all_frames.constructor.name !== 'TextFrame' && all_frames.constructor.name !== 'Graphic') { 

 

   all_frames.duplicate(current_layer); 

 

  } 

 

}

* You are right the variable «my» isn't useful in this code > It was a copy paste from the complete script.

I added my script which fix this on github. This is an alternative to «layer-cloner-1.3.jsxbin» and the code is readable.

This script is based on this libary «GitHub - bastienEichenberger/extendscript-library: ExtendScript-library is a JavaScript library. Thi... »

You can download the complete repository > then go extendscript-library/public-scripts/ImportLayers/ > run the file ImportLayersApp.jsx

Best regards,
Bastien

Votes

Translate

Translate

Report

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 ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

Hi Bastien,

thank you for sharing.

I copied the zip, extracted the zip, had two InDesign CS6 documents open, one named source-CS6.indd, one named target-CS6.indd and started ImportLayersApp.jsx with a double-click from my Scripts Panel where I moved all the contents of the extracted zip file.

An alert came up that was telling me to open the source document:

"Please open the source document before you run this script"

I asked myself: How is the script ImportLayersApp.jsx supposed to work?

Should I add code to it? And if yes, what exactly?

Then I opened ImportLayersApp.jsx in the ESTK and saw that the script will stop with exactly that alert if more than one document is open.

Maybe you should change the alert text to: "Have exactly one document open to run the script successfully." ?

Ok. Then I closed my target doc and the script ran as expected after assigning the target doc.

Some issues:

1. It does not handle threading of text frames in the target if necessary

( That would be a feature request, I guess 🙂 )

2. If the target does not contain the same number of spreads than the source some strange things will happen:

There is no error message. All frames of the spreads at the end of the source doc that are missing in target are simply duplicated to the first spread of the target. ( Workaround: Make sure that the number of spreads in target is at least the number of spreads in source.)

And of course:
Make sure that size of pages, number of pages per spread and pasteboard size are identical.

Tested with InDesign CS6 v 8.1.0 on Mac OS X 10.6.8.

Thanks,
Uwe

Votes

Translate

Translate

Report

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 ,
Jul 10, 2017 Jul 10, 2017

Copy link to clipboard

Copied

Hi Uwe,

Thank you for your feedback …
I will add some of your features request in few days!

Best,Bastien

Votes

Translate

Translate

Report

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 ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

Hi Uwe,

Hi just added a function to check the document integrity before the script runs.
Let me know if you have other comments.

About your feature request: keep threading of text frames.

Do you have any idea how to do this? Copy each element and relink them later?

Best regards,
Bastien

Votes

Translate

Translate

Report

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 ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

Author of the layer-cloner-1.3.jsxbin script here.

Yes, you have to copy each TF and then relink every threaded TF in reverse (from the last of the thread to the first), see the link below.

Here is the underlying code of my script (I had to create the jsxbin package because of dependencies): Layer cloner · GitHub

Votes

Translate

Translate

Report

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 08, 2017 May 08, 2017

Copy link to clipboard

Copied

EDIT: Faulty link i my reply, sorry. Here's the right one.
http://henriklideberg.se/?attachment_id=225

Votes

Translate

Translate

Report

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 ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

We had the exact same problem and we've made a script which we also give to our clients: https://redokun.com/blog/indesign-copy-entire-layer-one-file-another

The underlying implementation is basically the same as the one suggested by winterm, but we've added a UI so it's not necessary to edit the script every time the layer name changes.

Edit: Not using that approach anymore. This script has been re-written and now supports threaded TextFrames (which were split with the previous implementation). The updated version is available at the same URL.

Votes

Translate

Translate

Report

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
New Here ,
Jan 22, 2017 Jan 22, 2017

Copy link to clipboard

Copied

Hello As far as I'm concerned there's no direct way to copy layers, mainly because You could have a multiple pages in different documents thus copied layer could contain graphics and text assigned to page that doesn't exist in the new document.

In my work I use a workaround. I just copy pages between documents --> this copies the elements and layers from the previous document into the new document, and then I can distribute those elements to my choice

I hope this helps. Cheers.

Votes

Translate

Translate

Report

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
New Here ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

Hello there,

Please, i have to import a translate layer in InDesign 2018. I have more than 312 pages to translate. I can't find the script : layer-cloner-1.3.jsxbin, i already tried https://redokun.com/blog/indesign-copy-entire-layer-one-file-another  (but no return)

I would like to try some script, maybe someone can help me please ?

Have a good day

Loïc.

Votes

Translate

Translate

Report

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 ,
Mar 07, 2018 Mar 07, 2018

Copy link to clipboard

Copied

LATEST

It's unlikely that the author of that script will read your message in this forum.

In the forum thread, pause over the script writer's name. In the popup that appears, click "Message" to send a personal message.

Safari047.png

Votes

Translate

Translate

Report

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