Last active
December 27, 2015 07:39
-
-
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
This file contains hidden or 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 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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...