Created
April 12, 2016 22:01
-
-
Save gabovanlugo/98e4d42808f679fdd6142cc57e332246 to your computer and use it in GitHub Desktop.
Adobe Illustrator Script for exporting artboards to a selective density assets.
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
/** | |
* Remix by: @gabovanlugo (http://gabolugo.com) | |
* Thanks to: @herkulano, Niels Bosma & Hiroyuki Sato | |
*/ | |
main(); | |
var folder; | |
function main() { | |
/* | |
* UI Definition | |
*/ | |
// Window | |
var win = new Window('dialog', 'Export Artboards Assets'); | |
win.alignChildren = 'fill'; | |
// Panel for Checkboxes | |
win.scalePanel = win.add('panel', undefined, 'Scale'); | |
win.scalePanel.orientation = 'row'; | |
// Checkboxes Definition | |
win.scalePanel.s1 = win.scalePanel.add('checkbox', undefined, '@x'); | |
win.scalePanel.s2 = win.scalePanel.add('checkbox', undefined, '@2x'); | |
win.scalePanel.s3 = win.scalePanel.add('checkbox', undefined, '@3x'); | |
// Checkboxes Default Values | |
win.scalePanel.s1.value = true | |
win.scalePanel.s2.value = true | |
win.scalePanel.s3.value = false | |
// Action Buttons | |
win.btnGroup = win.add('group', undefined); | |
win.btnGroup.alignment = 'center'; | |
win.btnGroup.cancelBtn = win.btnGroup.add('button', undefined, 'Cancel'); | |
win.btnGroup.okBtn = win.btnGroup.add('button', undefined, 'OK'); | |
// UI Functions | |
win.btnGroup.okBtn.onClick = function () { | |
saveAllAssets( | |
win.scalePanel.s1.value, | |
win.scalePanel.s2.value, | |
win.scalePanel.s3.value | |
); | |
win.close(); | |
} | |
win.btnGroup.cancelBtn.onClick = function () { | |
win.close(); | |
} | |
win.show(); | |
} | |
function saveAllAssets(s1, s2, s3) { | |
folder = Folder.selectDialog(); | |
var document = app.activeDocument; | |
if (document && folder) { | |
if (s1) { | |
saveAssets(100, '', document); | |
} | |
if (s2) { | |
saveAssets(200, '@2x', document); | |
} | |
if (s3) { | |
saveAssets(300, '@3x', document); | |
} | |
} | |
alert('Done! Assets saved in: \n' + folder.fsName); | |
} | |
function saveAssets(scaleTo, densitySuffix, document) { | |
var i, ab, file, options; | |
for (i = document.artboards.length - 1 ; i >= 0 ; i--) { | |
document.artboards.setActiveArtboardIndex(i); | |
ab = document.artboards[i]; | |
file = new File(folder.fsName + '/' + ab.name + densitySuffix + '.png'); | |
options = new ExportOptionsPNG24(); | |
options.antiAliasing = true; | |
options.transparency = true; | |
options.artBoardClipping = true; | |
options.verticalScale = scaleTo; | |
options.horizontalScale = scaleTo; | |
document.exportFile(file, ExportType.PNG24, options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment