Last active
February 1, 2016 17:48
-
-
Save mir4a/8340958 to your computer and use it in GitHub Desktop.
Action for exporting every group items under first level of parent layer named icons. Tested on Adobe Illustrator CS5
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
// reference http://graphicdesign.stackexchange.com/a/26044/18833 | |
function exportFileToPNG(dest, artBoardIndex) | |
{ | |
var exportOptions = new ExportOptionsPNG24(); // or ExportOptionsPNG24 | |
var type = ExportType.PNG24; // or ExportType.PNG24 | |
var file = new File(dest + ".png"); | |
exportOptions.artBoardClipping = true; | |
exportOptions.antiAliasing = true; | |
exportOptions.transparency = true; | |
exportOptions.qualitySetting = 72; | |
exportOptions.saveMultipleArtboards = false; | |
exportOptions.artboardRange = "" + artBoardIndex; | |
app.activeDocument.exportFile( file, type, exportOptions ); | |
} | |
var docRef = app.activeDocument; | |
function execute(sel, folder,append) | |
{ | |
if (app.documents.length == 0) | |
{ | |
Window.alert('No document open', 'Error'); | |
return; | |
} | |
if (sel.length == 0) | |
{ | |
Window.alert('Nothing selected', 'Error'); | |
return; | |
} | |
var selectedStuff = sel; | |
// snap position to pixels | |
selectedStuff.position = [ Math.round(selectedStuff.position[0]), Math.round(selectedStuff.position[1]) ]; | |
// create temporary artboad for exporting | |
var rect = selectedStuff.visibleBounds; | |
try | |
{ | |
docRef.artboards.add(rect); | |
} | |
catch(e) | |
{ | |
Window.alert('Could not create Artboard as step of export.', 'Failure'); | |
return; | |
} | |
// determine destination | |
var fileName = sel.name.toLowerCase(); | |
var destFolder = folder; | |
if(destFolder) | |
{ | |
try | |
{ | |
exportFileToPNG(destFolder + "/" + fileName + append, docRef.artboards.length); | |
} | |
catch(e) | |
{ | |
Window.alert('Could not export to PNG','Error'); | |
return; | |
} | |
} | |
// delete temp-artboard | |
docRef.artboards.remove(docRef.artboards.length - 1); | |
} | |
var group_items = docRef.groupItems.length; | |
var icon_size = prompt ('Enter the value of exported icons', 64); | |
var file_prefix = prompt ('Do you need additional filename prefix?', ''); | |
var folder_to_save = Folder.selectDialog('Select the folder to export to:'); | |
for (var i = 0; i < group_items; i++) | |
{ | |
var current_group = docRef.groupItems[i]; | |
// Window.alert (current_group.layer, 'Parent') | |
$.writeln(icon_size); | |
if (current_group.parent.name == 'icons') | |
{ | |
var group_height = current_group.height; | |
var resize_ratio = icon_size/group_height * 100; | |
current_group.resize(resize_ratio,resize_ratio); | |
$.writeln(current_group.width); | |
execute(current_group,folder_to_save,file_prefix); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment