Created
August 14, 2019 05:46
-
-
Save teckliew/d64c864a9d959d74273d744f5dd3d4d8 to your computer and use it in GitHub Desktop.
Adobe Illustrator script that exports SVG for every layer in the document.
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
/********************************************************** | |
ExportSVGLayers.jsx | |
DESCRIPTION | |
For Adobe Illustrator. | |
This script takes your active document and export one | |
SVG per layer. | |
Best used for exporting many layers with the same artboard | |
size into individual SVG files. | |
INSTRUCTIONS | |
Hide all layers first before running script. | |
**********************************************************/ | |
if ( app.documents.length > 0 ) { | |
doc = app.activeDocument; | |
if(!doc.saved){ | |
Window.alert("This script needs to modify your document. Please save it before running this script."); | |
} | |
}else{ | |
Window.alert("You must open at least one document."); | |
} | |
function exportFileToSVG(dest) { | |
if (app.documents.length > 0) { | |
var options = new ExportOptionsSVG(); | |
options.embedRasterImages = true; | |
options.embedAllFonts = false; | |
options.fontSubsetting = SVGFontSubsetting.GLYPHSUSED; | |
options.cssProperties = SVGCSSPropertyLocation.PRESENTATIONATTRIBUTES; | |
options.fontSubsetting = SVGFontSubsetting.None; | |
options.documentEncoding = SVGDocumentEncoding.UTF8; | |
var type = ExportType.SVG; | |
var fileSpec = new File(dest); | |
app.activeDocument.exportFile(fileSpec, type, options); | |
} | |
} | |
function exportSVGPerLayer(doc) { | |
//document file path | |
var filePath = doc.path.fsName; | |
//get the total number of layers in the active document | |
var totalLayers = doc.layers.length; | |
//looping on layers to export one SVG per layer | |
for ( var i = 0 ; i < totalLayers ; i++ ){ | |
var currentLayer = doc.layers[i]; | |
var layerName = currentLayer.name; | |
//Unlock the layer if needed and make visible | |
currentLayer.locked = false; | |
currentLayer.visible = true; | |
//Set destination and filename and then export | |
var destPath = filePath + "/" + layerName; | |
exportFileToSVG(destPath); | |
//Hide layer | |
currentLayer.visible = false; | |
} | |
} | |
exportSVGPerLayer(doc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment