Last active
February 11, 2017 15:24
-
-
Save pstaender/6c072a68c80ab6113e25c09f9521a9a4 to your computer and use it in GitHub Desktop.
This file contains 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
#target Illustrator | |
// script.name = exportLayersAsCSS_PNGs.jsx; | |
// script.description = mimics the Save for Web; | |
// script.requirements = an open document; tested with CS5 on Windows. | |
// script.parent = carlos canto // 05/24/13; All rights reserved | |
// script.elegant = false; | |
// Source: http://graphicdesign.stackexchange.com/questions/20459/how-to-export-illustrator-layers-as-individual-images | |
/** | |
* export layers as PNG | |
* @author Niels Bosma, CarlosCanto and Philipp Staender | |
*/ | |
if (app.documents.length > 0) { | |
main(); | |
} | |
else alert('Cancelled by user'); | |
function main() { | |
var document = app.activeDocument; | |
var afile = document.fullName; | |
var filename = afile.name.split('.')[0]; | |
var folder = afile.parent.selectDlg("Export as CSS Layers (images only)..."); | |
if (folder != null) { | |
var activeABidx = document.artboards.getActiveArtboardIndex(); | |
var activeAB = document.artboards[activeABidx]; // get active AB | |
var abBounds = activeAB.artboardRect;// left, top, right, bottom | |
showAllLayers(); | |
var docBounds = document.visibleBounds; | |
activeAB.artboardRect = docBounds; | |
var options = new ExportOptionsPNG24(); | |
options.antiAliasing = true; | |
options.transparency = true; | |
options.artBoardClipping = true; | |
var n = document.layers.length; | |
hideAllLayers(); | |
for (var i = n - 1, k = 0; i >= 0; i--, k++) { | |
//hideAllLayers(); | |
var layer = document.layers[i]; | |
layer.visible = true; | |
var file = new File(folder.fsName + '/' + layer.name + ".png"); | |
document.exportFile(file, ExportType.PNG24, options); | |
layer.visible = false; | |
} | |
showAllLayers(); | |
activeAB.artboardRect = abBounds; | |
} | |
function hideAllLayers() { | |
forEach(document.layers, function (layer) { | |
layer.visible = false; | |
}); | |
} | |
function showAllLayers() { | |
forEach(document.layers, function (layer) { | |
layer.visible = true; | |
}); | |
} | |
function forEach(collection, fn) { | |
var n = collection.length; | |
for (var i = 0; i < n; ++i) { | |
fn(collection[i]); | |
} | |
} | |
} |
This file contains 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
// script.name = export_illustrator_layers_to_svg.jsx; | |
// script.description = mimics the Save for Web; | |
// script.requirements = an open document; tested with CS5 on Windows. | |
// script.parent = carlos canto // 05/24/13; All rights reserved | |
// script.elegant = false; | |
// Source: http://graphicdesign.stackexchange.com/questions/20459/how-to-export-illustrator-layers-as-individual-images | |
/** | |
* export layers as PNG | |
* @author Niels Bosma, CarlosCanto and Philipp Staender | |
*/ | |
if (app.documents.length > 0) { | |
main(); | |
} | |
else alert('Cancelled by user'); | |
function main() { | |
var document = app.activeDocument; | |
var afile = document.fullName; | |
var filename = afile.name.split('.')[0]; | |
var folder = afile.parent.selectDlg("Export as CSS Layers (images only)..."); | |
if (folder != null) { | |
var activeABidx = document.artboards.getActiveArtboardIndex(); | |
var activeAB = document.artboards[activeABidx]; // get active AB | |
var abBounds = activeAB.artboardRect;// left, top, right, bottom | |
showAllLayers(); | |
var docBounds = document.visibleBounds; | |
activeAB.artboardRect = docBounds; | |
var options = new ExportOptionsSVG(); | |
options.antiAliasing = true; | |
options.transparency = true; | |
options.artBoardClipping = true; | |
var n = document.layers.length; | |
hideAllLayers(); | |
for (var i = n - 1, k = 0; i >= 0; i--, k++) { | |
//hideAllLayers(); | |
var layer = document.layers[i]; | |
layer.visible = true; | |
var file = new File(folder.fsName + '/' + layer.name + ".svg"); | |
document.exportFile(file, ExportType.SVG, options); | |
layer.visible = false; | |
} | |
showAllLayers(); | |
activeAB.artboardRect = abBounds; | |
} | |
function hideAllLayers() { | |
forEach(document.layers, function (layer) { | |
layer.visible = false; | |
}); | |
} | |
function showAllLayers() { | |
forEach(document.layers, function (layer) { | |
layer.visible = true; | |
}); | |
} | |
function forEach(collection, fn) { | |
var n = collection.length; | |
for (var i = 0; i < n; ++i) { | |
fn(collection[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment