Is there a way to batch export Illustrator symbols as pngs?

I use Illustrator as my main graphics program for building modular UI components.

enter image description here

Context: I’m exploring an animation software, Pixate, and will need to upload all UI assets to the project library — is there any way to make this any easier by somehow batch exporting all the symbols in a Symbol Library?

I have not yet been able to find a solution online that solves this, and would appreciate any direction!

Answer

The following script will export all your symbols from the symbol library and save them to a chosen folder.

You just have to make sure all your layers are hidden first.

var doc = app.activeDocument;
var symbolCount = doc.symbols.length;

if (symbolCount >= 1) {

    if (confirm("Are all your layers hidden?")) {

        // create temp layer
        doc.layers.add();

        // create directory
        var dest = Folder.selectDialog();
        dest.create();

        // loop through symbols
        for (var i = 0; i < doc.symbols.length; i++) {

            // place a symbol instance - temp
            var s = doc.symbolItems.add(doc.symbols[i]);         

            // assign name
            var filename = (doc.symbols[i].name)

            // export symbols
            savePNG(dest, filename);

            // delete temp symbol instance
            s.remove();
        }
        // remove temp layer
        doc.layers[0].remove();
    }

    function savePNG(dest, filename) {
        // save options
        var type = ExportType.PNG24;
        var options = new ExportOptionsPNG24();
        options.transparency = true;

        // file
        var file = new File(dest + "/" + filename);

        // export
        doc.exportFile(file, type, options);
    }

} else {
    alert("You don't have any symbols in this document");
}

You can find this script at: https://gist.github.com/shaneparsons/1717f21a757f24fb4559

Attribution
Source : Link , Question Author : ksy , Answer Author : Shane

Leave a Comment