Copy link to clipboard
Copied
Hello, I already work creating some scripts, but very simple things. I have several .AI files in a folder. Within these files there is only one Group. I need a way to insert these files into a document open in Illustrator with its editing capabilities intact. It would be like opening a file, copying and pasting it into my document. But it is not feasible to do this with multiple files. I need ideas.
Hi @MarcosAdriano1994, you can try this script I just wrote. When you run it, it will duplicate all the page items into the active document. Let me know if it helps.
- Mark
/**
* Gather page items from all documents into active document.
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/create-a-script-to-insert-ai-within-a-document-ai/m-p/14442488
*/
(function () {
var docs = app.documents;
if (docs.length < 2)
return alert('Please open t
...
Copy link to clipboard
Copied
Hi @MarcosAdriano1994, you can try this script I just wrote. When you run it, it will duplicate all the page items into the active document. Let me know if it helps.
- Mark
/**
* Gather page items from all documents into active document.
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/create-a-script-to-insert-ai-within-a-document-ai/m-p/14442488
*/
(function () {
var docs = app.documents;
if (docs.length < 2)
return alert('Please open two or more documents and try again.');
var sourceDocNames = [],
targetDoc = docs[0];
for (var i = 1; i < docs.length; i++)
sourceDocNames.push(docs[i].name);
for (var i = 0, sourceDoc, items, layer; i < sourceDocNames.length; i++) {
sourceDoc = app.documents.getByName(sourceDocNames[i]);
for (var j = sourceDoc.layers.length -1; j >= 0 ; j--) {
items = sourceDoc.layers[j].pageItems;
layer = makeLayer(targetDoc, sourceDoc.layers[j]);
for (var k = 0; k < items.length; k++)
items[k].duplicate(layer, ElementPlacement.PLACEATEND);
}
}
})();
/**
* Makes, or gets, a layer.
* @author m1b
* @version 2022-07-24
* @param {Document} [doc] - an Illustrator Document.
* @param {String|Layer} [nameOrLayer] - the layer name, or a Layer.
* @returns {Layer}
*/
function makeLayer(doc, nameOrLayer) {
doc = doc || app.activeDocument;
var newLayer,
name = nameOrLayer.hasOwnProperty('name') ? nameOrLayer.name : nameOrLayer;
try {
newLayer = doc.layers.getByName(name);
} catch (e) {
newLayer = doc.layers.add();
if (undefined != nameOrLayer) {
newLayer.name = name;
if (nameOrLayer.hasOwnProperty('color'))
newLayer.color = nameOrLayer.color;
}
}
return newLayer;
};
Copy link to clipboard
Copied
Apologies for the delay. I adapted your code and it worked perfectly. Thank you very much.
Copy link to clipboard
Copied
Excellent! Well done! 😊