Skip to content

Instantly share code, notes, and snippets.

@gilbarbara
Created March 31, 2017 21:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilbarbara/6f3662f2c43128b321fcd80e56e30d70 to your computer and use it in GitHub Desktop.
Save gilbarbara/6f3662f2c43128b321fcd80e56e30d70 to your computer and use it in GitHub Desktop.
Export Illustrator layers to SVG files
var doc = app.activeDocument;
try {
if (app.documents.length > 0) {
var exportOpts = new ExportOptionsSVG();
if (doc.saved == false) {
doc.save();
}
for (i = 0; i < doc.layers.length; i++) {
if (doc.layers[i].locked == false) {
doc.layers[i].visible = false;
}
}
fullDocName = doc.fullName;
var param = doc.name.split('.');
realDocName = param[0];
for (i = 0; i < doc.layers.length; i++) {
if (i - 1 < 0) {
doc.layers[i].visible = true;
} else {
doc.layers[i - 1].visible = false;
doc.layers[i].visible = true;
}
if (doc.layers[i].locked == false) {
docName = realDocName + doc.layers[i].name + ".svg";
var targetFile = new File(doc.path + "/" + docName);
doc.exportFile(targetFile, ExportType.SVG, exportOpts);
}
}
doc.close(SaveOptions.DONOTSAVECHANGES);
doc = null;
app.open(fullDocName);
}
} catch (e) {
alert(e.message, "Script Alert", true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment