-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSave Layers to SVG.jsx
85 lines (72 loc) · 2.37 KB
/
Save Layers to SVG.jsx
1
if(app.documents.length > 0){ var docRef = app.activeDocument; var myDestination = Folder.selectDialog("Choose a save destination"); if(myDestination){ saveLayersToFolder(myDestination); }}function copyDocument(doc){ var preset = new DocumentPreset(); preset.width = doc.width; preset.height = doc.height; preset.colorMode = doc.documentColorSpace; preset.units = doc.rulerUnits; var copy = app.documents.addDocument(doc.documentColorSpace, preset); return copy;}function copyLayer(from, to){ to.artworkKnockout = from.artworkKnockout; to.blendingMode = from.blendingMode; to.color = from.color; to.dimPlacedImages = from.dimPlacedImages; to.isIsolated = from.isIsolated; to.name = from.name; to.opacity = from.opacity; to.preview = from.preview; to.printable = from.printable; to.sliced = from.sliced; to.typename = from.typename; var items = from.pageItems; copyLayerItems(items, to); return to;}function copyLayerItems(items, to){ for(var i=0; i<items.length; ++i){ var item = items[i].duplicate(to, ElementPlacement.PLACEATEND); }}function saveLayersToFolder(folder){ hideAllLayers(docRef); var totalLayers = docRef.layers.length; var layerIndex; var layer; for(layerIndex = 0; layerIndex < totalLayers; layerIndex++) { layer = docRef.layers[layerIndex]; layer.visible = true; var copyDoc = copyDocument(docRef); var copyDocLayer = copyLayer(layer, copyDoc.layers.add()); var saveAsFileName = folder.fullName + "/" + layer.name + ".svg"; var saveOpts = new ExportOptionsSVG(); var saveType = ExportType.SVG; var saveFile = new File(saveAsFileName); saveOpts.DTD = SVGDTDVersion.SVG1_0; saveOpts.documentEncoding = SVGDocumentEncoding.UTF8; saveOpts.cssProperties = SVGCSSPropertyLocation.PRESENTATIONATTRIBUTES; copyDoc.exportFile(saveFile, saveType, saveOpts); layer.visible = false; copyDoc.close(); copyDoc = null; }}function hideAllLayers(document){ var totalLayers = document.layers.length; var layerIndex; var layer; for(layerIndex = 0; layerIndex < totalLayers; layerIndex++) { layer = document.layers[layerIndex]; layer.visible = false; }}