Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for Show only | Search instead for Did you mean:/t5/indesign-discussions/how-to-import-a-layer-from-one-document-into-a-new-untitled-document/td-p/13097630 Jul 27, 2022 Jul 27, 2022
Copy link to clipboard
I have an indesign file that I use as a template for other indesign files. The file has one layer that is a tile page which I copy and paste onto other documents. I'd like to write a script that lauches a new document with that layer already brought over from my template. I have some ideas but I'm getting stuck.
In short, I can create a new document by writing:
var myDocument = app.documents.add()
But I'm not sure how to properly call for the layer from my template file and then paste it into my new document. I know I can open the template file using:
app.open(File('C:/Users/userprofile/Documents/Template_file.indd'))
And then start working in that file. but I don't what to do that because then I may accidentally save over the template file.
I need to know if I can reference an indesign file and its layers without actually opening it.
Another option would be to open the template file but as a new untiled document? If thats possible?
Any ideas are appreciated.
Community guidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
You can open the template file as a copy:
app.open(File('C:/Users/userprofile/Documents/Template_file.indd')), true, OpenOptions.OPEN_COPY);
Or just save the doc as an INDT file.
1 1 Upvote 4 Replies 4 Community Expert ,/t5/indesign-discussions/how-to-import-a-layer-from-one-document-into-a-new-untitled-document/m-p/13097651#M486082 Jul 27, 2022 Jul 27, 2022
Copy link to clipboard
You can open the template file as a copy:
app.open(File('C:/Users/userprofile/Documents/Template_file.indd')), true, OpenOptions.OPEN_COPY);
Or just save the doc as an INDT file.
1 1 Upvote Community guidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,/t5/indesign-discussions/how-to-import-a-layer-from-one-document-into-a-new-untitled-document/m-p/13097660#M486083 Jul 27, 2022 Jul 27, 2022
Copy link to clipboard
I see it as important that all of my documents have the same name and same order to be able to copy and paste from one document to the other as layer names are remembered, their order not.
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,/t5/indesign-discussions/how-to-import-a-layer-from-one-document-into-a-new-untitled-document/m-p/13098430#M486122 Jul 28, 2022 Jul 28, 2022
Copy link to clipboard
@Ben-ind said: "I'd like to write a script that lauches a new document with that layer already brought over from my template."
do you want just an additional layer with the layer's name from your template?
Or do you also want other properties of this layer like layer color?
See into DOM documentation, into properties with read/write access:
Note: Method move() with object layer cannot move a layer from one document to another.
It just moves the layer in the layer stack of the same document.
If both documents are open, no other document, and your template document is not the active one , you could act like this where the new document is the target and the source, your template is not the currently active document.
If the layer is not present in the target document, so targetLayer is not valid, the script will add a new layer in the target with the same properties of the source layer. If a layer with the same name is already in the target document, it will update all properties from the source layer:
var targetDoc = app.documents[0]; var sourceDoc = app.documents[1]; var layerName = "MyLayerName"; var sourceLayer = sourceDoc.layers.itemByName( layerName ); if( !sourceLayer.isValid ) < alert( "ERROR: Layer of source not found." ); exit(); >; var targetLayer = targetDoc.layers.itemByName( layerName ); if( !targetLayer.isValid ) < targetDoc.layers.add ( sourceLayer.properties ); >else < targetLayer.properties = sourceLayer.properties >;
IMPORTANT: What this does not handle is the stacking order of layers in the Layers panel.
Regards,
Uwe Laubender
( Adobe Community Professional )
EDITED code and added a direct test for the layer in the source document.