Copy link to clipboard
Copied
Hello Community There will be a script that copied all the content of "Various Artboards" from a document and pasted it to a new document automatically. I know that there are several options in Illustrator that copy the content but from a single artboard and the other option is to copy with the artboards and I only want the content to pass it to a new document.
Copy link to clipboard
Copied
Hi @lizardo_4752, you have said you need to copy the artwork from some artboards to a new document. But why do you need a script for it? It is just a matter of selecting and copy/pasting. There must be reason a script is needed. Please tell us more. 🙂
- Mark
Copy link to clipboard
Copied
Hello @m1b , how are you? Thank you for responding. I'll give you a script that more or less does what I want. I mean copying only the content of several artboards without the artboards and combining them with other files in a new document, since having to open them one by one is a lot of time. I work in a printing press where many files are moved. The script only copies from one artboard and I would like it to copy from all of them.
var sourceFolder = Folder.selectDialog('Selecciona la carpeta con los archivos de Illustrator a combinar');
if (sourceFolder) {
var files = sourceFolder.getFiles("*.ai"); // Filtra solo archivos .ai
if (files.length > 0) {
// Crear un nuevo documento
var destDoc = app.documents.add();
for (var i = 0; i < files.length; i++) {
var sourceDoc = app.open(files[i]);
var sourceArtboards = sourceDoc.artboards;
// Crear una capa en el documento destino con el nombre del archivo
var newLayer = destDoc.layers.add();
newLayer.name = files[i].name.replace(/\.ai$/, '');
// Iterar sobre cada mesa de trabajo en el documento fuente
for (var j = 0; j < sourceArtboards.length; j++) {
// Seleccionar la mesa de trabajo actual
sourceDoc.artboards.setActiveArtboardIndex(j);
var artboard = sourceArtboards[j];
var artboardRect = artboard.artboardRect;
// Seleccionar todos los objetos en la mesa de trabajo actual
app.selection = null;
app.executeMenuCommand('selectallinartboard');
// Copiar los objetos seleccionados
app.executeMenuCommand('copy');
// Cambiar al documento destino
app.activeDocument = destDoc;
// Asegurarse de que la capa nueva esté activa
destDoc.activeLayer = newLayer;
// Pegar el contenido en la posición correcta
app.executeMenuCommand('pasteInPlace');
// Mover los objetos pegados a la posición correcta
var pastedItems = destDoc.selection;
var offsetX = artboardRect[0] - destDoc.artboards[0].artboardRect[0];
var offsetY = artboardRect[1] - destDoc.artboards[0].artboardRect[1];
for (var k = 0; k < pastedItems.length; k++) {
pastedItems[k].translate(-offsetX, offsetY);
}
}
// Cerrar el documento fuente sin guardar cambios
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
}
alert('Archivos combinados en un solo documento');
} else {
alert('No se encontraron archivos .ai en la carpeta seleccionada');
}
} else {
alert('No se seleccionó ninguna carpeta');
}