Copy link to clipboard
Copied
Hi, I am working with very heavy files that I need to merge. In order to do so I manually split up the file based on the objects colours from a printed PDF (the file is too large and the save PDF compatible is too buggy to link an Illustrator file). I then copy over simple objects to retain the layer names and structure prior to embedding the PDF and relocating the objects back to their original layer.
I was therefore wondering, can I prepopulate all my layers/ only selected layers with a simple object to be able to copy the simple objects and thereby the layer structure over to another Illustrator file? Is there a script for this?
Here you go. I think this does what you want. Check line 44 if you want to predefine which layers to use instead of just copying all of them.
github link: https://github.com/wdjsdev/public_illustrator_scripts/blob/master/copy_layers_to_new_doc.js
code:
/*
Script Name: copy layers to new doc
Author: William Dowling
Email: illustrator.dev.pro@gmail.com
Forum Post: https://community.adobe.com/t5/illustrator/prepopulate-layers-with-simple-object-i-e-rectangle/td-p/11981726
If you find thi
...
Copy link to clipboard
Copied
i'm not really sure what you're trying to do here. are you creating rectangles on the layers so you can copy all the artwork and then paste it (with paste remembers layers turned on) into a new document to get the same layer structure in the new document? And you're asking for a function to create a rectangle on every layer so that you can do the copy paste?
Copy link to clipboard
Copied
Correct, that's exactly what I am aiming at.
Copy link to clipboard
Copied
if you're not copying any actual artwork over, how about doing a saveAs() on the active document to make a duplicate of it, then delete all the artwork out of it so you're just left with a file with the same layer structure?
Copy link to clipboard
Copied
That is because I need to merge multiple documents into one, though each document needs to be on seperate layer 😉
The files contain different maps from different times.
Copy link to clipboard
Copied
Here you go. I think this does what you want. Check line 44 if you want to predefine which layers to use instead of just copying all of them.
github link: https://github.com/wdjsdev/public_illustrator_scripts/blob/master/copy_layers_to_new_doc.js
code:
/*
Script Name: copy layers to new doc
Author: William Dowling
Email: illustrator.dev.pro@gmail.com
Forum Post: https://community.adobe.com/t5/illustrator/prepopulate-layers-with-simple-object-i-e-rectangle/td-p/11981726
If you find this free script useful,
please consider buying me a cup of coffee to say thanks. =)
Paypal: paypal.me/illustratordev
Description: Create a new document with a layer structure matching
the current active document. Since layers cannot be directly copied
the following "workaround" is used:
create a rectangle in each layer and sublayer of
document, then copy/paste all rectangles into new document
with "pasteRemembersLayers" turned on to recreate layer
structure in new document. Then remove all the temp rectangles
so that the original file is unchanged, and the new file just
has empty layers matching the original document.
Alternatively you can define an array of layers if you only
want to bring in certain top level layers. See comment in code below
All child sublayers will come in along with any layer you copy.
*/
#target Illustrator
function copyLayersToNewDoc()
{
var doc = app.activeDocument;
var layers = doc.layers;
//copy all layers and sublayers
var layersToCopy = layers;
//alternatively, you could feed in a specific
//set of layers if you only want to copy some of them.
//you can get layers by index or by name
//
// var layersToCopy = [layers[0], layers["My Layer"]];
function addRects(layers)
{
for(var x=0;x<layers.length;x++)
{
rects.push(layers[x].pathItems.rectangle(0,0,50,50));
if(layers[x].layers.length)
{
addRects(layers[x].layers);
}
}
}
function copyRects(rects)
{
doc.selection = null;
for(var x=0;x<rects.length;x++)
{
rects[x].selected = true;
}
app.copy();
}
function removeRects(rects)
{
for(var x= rects.length-1;x>=0;x--)
{
rects[x].remove();
}
}
var rects = [];
addRects(layersToCopy);
copyRects(rects);
app.pasteRemembersLayers = true;
var newDoc = app.documents.add();
app.executeMenuCommand("pasteInPlace");
app.pasteRemembersLayers = false;
removeRects(newDoc.selection);
removeRects(rects);
}
copyLayersToNewDoc();
Copy link to clipboard
Copied
If you turn on Paste Remembers Layers in the Layers panel, layers will be created after copying if they don't exist in the target document and existing layers with the same name will be populated with the copied content.