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
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
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
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
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
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
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
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
Copy link to clipboard
Copied
EDIT: Faulty link i my reply, sorry. Here's the right one.
http://henriklideberg.se/?attachment_id=225
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.
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.
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.
Copy link to clipboard
Copied
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.