Created
March 31, 2017 21:51
-
-
Save gilbarbara/6f3662f2c43128b321fcd80e56e30d70 to your computer and use it in GitHub Desktop.
Export Illustrator layers to SVG files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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