Skip to content

Instantly share code, notes, and snippets.

@shaneparsons
Last active May 19, 2016 16:26
Show Gist options
  • Save shaneparsons/fffd6bc6f8e80f84a381 to your computer and use it in GitHub Desktop.
Save shaneparsons/fffd6bc6f8e80f84a381 to your computer and use it in GitHub Desktop.
Illustrator Script - Batch Export Symbols as SVGs
var doc = app.activeDocument;
var symbolCount = doc.symbols.length;
if (symbolCount >= 1) {
if (confirm("Are all your layers hidden?")) {
// choose directory
var dest = Folder(doc.path).selectDlg();
// folder chosen
if (dest) {
// create temp layer
doc.layers.add();
// create temp artboard
doc.artboards.add(doc.artboards[0].artboardRect);
// get temp artboard
var tempAB = doc.artboards.getActiveArtboardIndex();
// loop through symbols
for (var i = 0; i < doc.symbols.length; i++) {
// place a symbol instance - temp
var symbol = doc.symbolItems.add(doc.symbols[i]);
// resize artboard
doc.artboards[tempAB].artboardRect = doc.visibleBounds;
app.redraw();
// choose directory
var filename = doc.symbols[i].name;
// export symbols
saveSVG(dest, filename);
// delete temp symbol instance
symbol.remove();
}
// remove temp layer
doc.layers[0].remove();
// remove temp artboard
doc.artboards[tempAB].remove();
}
}
function saveSVG(dest, filename) {
// save options
var type = ExportType.SVG;
var options = new ExportOptionsSVG();
// file
var file = new File(dest + "/" + filename);
// export
doc.exportFile(file, type, options);
}
} else {
alert("You don't have any symbols in this document");
}
@shaneparsons
Copy link
Author

shaneparsons commented May 19, 2016

Note: This script seems to have issues since Illustrator added dynamic symbols. I wouldn't recommend using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment