Illustrator script: individual layer multiformat export.
Hi Everyone. I've been trying to figure out how to put together a script that would allow me to export individual layers into different formats: .ai, .pdf, .png, .dxf, .eps, .jpg, .svg. I really have very low experience and understanding of scripts, so I'd really appreciate it if someone could point me in the right direction.
Basically, I have a file with different illustrations on each layer, I want to first save each layer as a new AI file and hopefully from that file (or maybe at the same time) export to all the mentioned formats.
I tried with other multiexporter scripts but didn't find anyone that would do the .ai save and then the exports. And also had trouble with most where instead of exporting the individual layers (individual illustrations) it exports the whole artboard with all the illustrations in it, which is not what I need.
Does anyone know of a script that might be able to do this? if it possible to do it with just one script?
I'd really appreciate any help I can get.
P.S.: I've been working with a script from Carlos Canto (below), trying to add the .ai save option unsuccessfully. But wasn't able to get it to work. It doesn't export the individual layers, rather the whole artboard with all the images. So really wondering if I'm doing something wrong before running the script?
#target Illustrator
// script.name = exportLayersAsCSS_PNGs.jsx;
// script.description = mimics the Save for Web, export images as CSS Layers (images only);
// script.requirements = an open document; tested with CS5 on Windows.
// script.parent = carlos canto // 05/24/13; All rights reseved
// script.elegant = false;
/**
* export layers as PNG
* @7111211 Niels Bosma
*/
// Adapted to export images as CSS Layers by CarlosCanto
if (app.documents.length>0) {
main();
}
else alert('Cancelled by user');
function main() {
var document = app.activeDocument;
var afile = document.fullName;
var filename = afile.name.split('.')[0];
var folder = afile.parent.selectDlg("Export as CSS Layers (images only)...");
if(folder != null)
{
var activeABidx = document.artboards.getActiveArtboardIndex();
var activeAB = document.artboards[activeABidx]; // get active AB
var abBounds = activeAB.artboardRect;// left, top, right, bottom
showAllLayers();
var docBounds = document.visibleBounds;
activeAB.artboardRect = docBounds;
var options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
options.artBoardClipping = true;
var n = document.layers.length;
hideAllLayers ();
for(var i=0; i<n; ++i)
{
//hideAllLayers();
var layer = document.layers;
layer.visible = true;
var file = new File(folder.fsName + '/' +filename+ '-' + i+".png");
document.exportFile(file,ExportType.PNG24,options);
layer.visible = false;
}
showAllLayers();
activeAB.artboardRect = abBounds;
}
function hideAllLayers()
{
forEach(document.layers, function(layer) {
layer.visible = false;
});
}
function showAllLayers()
{
forEach(document.layers, function(layer) {
layer.visible = true;
});
}
function forEach(collection, fn)
{
var n = collection.length;
for(var i=0; i<n; ++i)
{
fn(collection);
}
}
}
