Skip to content

Instantly share code, notes, and snippets.

@julik
Last active December 27, 2015 07:39
Show Gist options
  • Save julik/7291071 to your computer and use it in GitHub Desktop.
Save julik/7291071 to your computer and use it in GitHub Desktop.
Export every Illustrator artboard to SVG without resaving your file under different names and showing you any dialogs
var exportToDir = "/Users/julik/Code/apps/mvp/public/icons/";
/* Crop every icon in your Illustrator file witha named artboard. This script will export them all */
var docRef = app.activeDocument;
docRef.save();
// Get the source path
var originalPath = app.activeDocument.fullName.toString();
// Allocate a copy of the current document that we will throw away. We do this
// since doing an exportFile() renames the active document and it needs to be resaved to a
// different place
var tempFile = new File('/tmp/tosvg.ai')
docRef.saveAs(tempFile);
var exportOptions = new ExportOptionsSVG();
for (var i = 0; i < docRef.artboards.length; i++ ) {
var artboardName = docRef.artboards[i].name.toLowerCase();
var destPath = exportToDir + "/" + artboardName + ".svg";
var destFile = new File(destPath);
docRef.artboards.setActiveArtboardIndex(i);
docRef.exportFile(destFile, ExportType.SVG, options);
}
// Close the copy of the document we have created
docRef.close()
// Reopen the original document
var originalFile = new File(originalPath);
app.open(originalFile);
@julik
Copy link
Author

julik commented Nov 3, 2013

Expounded upon here: http://www.ericson.net/content/2011/06/export-illustrator-layers-andor-artboards-as-pngs-and-pdfs/ but it didn't handle SVGs natively, so before I'd go there and update it...

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