• Editor
  • Adobe illustrator save [sub]layers to png (script)

Script from spin package doesn't save sublayers.
following script solve this problem
it creates folder structure the same as layer structure in AI and save visible layers to png files

var options = new ExportOptionsPNG24();
var doc = app.activeDocument;
var newdoc = app.documents.add(doc.documentColorSpace, doc.width, doc.height);
newdoc.artboards[0].artboardRect = doc.artboards[0].artboardRect;
saveSubLayers(doc, "");
newdoc.close(SaveOptions.DONOTSAVECHANGES);
function saveSubLayers(node, path){
    for (var i=0; i<node.layers.length; i++){
        var layer = node.layers[i];
        if (!layer.visible) 
                continue;
        if (layer.layers.length > 0){
             saveSubLayers(layer, path+"/"+layer.name);
        } else {
            saveLayer(layer, path);
        }        
} } function saveLayer(layer, path){ newdoc.layers[0].remove(); var newlayer = newdoc.layers[0]; for (var ii = layer.pageItems.length - 1; ii >= 0; ii --- ) layer.pageItems[ii].duplicate(newlayer, ElementPlacement.PLACEATBEGINNING); new Folder(doc.path + path).create(); newdoc.exportFile(new File(doc.path + path + "/" + layer.name + ".png"), ExportType.PNG24, options); }
Related Discussions
...

Nice, thanks for sharing!

Умничка!

5 mois plus tard

Hi everyone!

Thank you for the script. Works fine!!! Is it possible to add a line to get a json file, too?
I have seen that such a script is available for photoshop, but we work with adobe illustrator.

By the way Spine is a wonderful piece of software!
Thank you!

Nice. I wrote a similar thing for Flash if anybody wants it.

I´ll try again ;-)

Is it possible to add a line to get a json file, too?
I have seen that such a script is available for photoshop, but we work with adobe illustrator.

The illustrator and Photoshop script are very different but I guess it should be possible to add. I can look into it else we'll need to wait for Nate to come back it's been a very long time since the illustrator script was done.

8 jours plus tard

Thank you. That would help us so much!


Me again. :-) Sorry for pushing.
When will Nate come back?

I have a problem with the script. 🙁
I don't know what went wrong, but when I launch it, the java console pops up and says "trying to save".
I can see each of my layers showing as if extracted, but in the created folders there is only a few of them.

Does anybody have any idea about how can I solve this?


Apparently the problem comes from having too many sub-folders.
I cheated by using the command "assemble on a new layer" (working with the french version of AI, don't know the english name, sorry TT).

Can someone tweak the code a bit to add sub-sub folders (and maybe even sub-sub-sub-sub folders)?
Sorry for being pushy.

Many thanks!

6 jours plus tard

Please help.
Is it possible to add a line into the script above to get a json file?
Would make our workflow so much easier!!!

Thank you!

Haven't had time to look into this yet. It requires a pretty big rewrite. I'll try to find the time for it next week. Sorry

Thank you so much!!!

:yes: