Copy link to clipboard
Copied
I'm am SO DEVASTATED that CS6 got rid of the option to save as CSS layers in Save for Web. I just updated from 5 to 6 and now I'm looking for an alternative but am having no luck. I've tried some scripts I've found online but none of them work the way I need, or at all.
I do animation in AI where each layer is a frame on the animation. In CS5 I could Save for Web and check the Export as CSS Layers box. This would export all the layers in my AI file to pngs, where each layer is it's own png file, in one folder. I could then import them as an image sequence in Photoshop and turn layers on and off with each frame to create my animation.
I tried exporting my AI file to a PSD file with maximum editability but the more complicated the animation (meaning the more layers and the more objects on each layer) it would start flattening layers without warning. Not to mention the rendering time just opening the file in Photoshop and then trying to save it there once I had created all my frames. Photoshop froze on me 6 times this morning while I was trying things out.
I'm desperate for a simple way to do the CSS layer trick. If I can't find one, I'm going to have to go back to CS5 permanently, or until I can find a solution.
Copy link to clipboard
Copied
I don't understand the question, does the second script not work as expected?
Copy link to clipboard
Copied
I'm afraid it doesn't. I have a file with 57 layers I need to export as pngs, but it exports 3,364 layers instead, all but 57 have nothing on them and they're random sizes. I think I'll see if I can get that first code you posted to work again. That one worked a treat!
Copy link to clipboard
Copied
A pretty generous script. You want 60 images? Nah, get at least 3000.
Copy link to clipboard
Copied
I wonder why, it works fine here, can you try with another file with a couple of layers only? or can you share the files with 57 layers to try to find out why you're getting 3000 pngs?
Copy link to clipboard
Copied
It was such a weird problem. It was only doing it for 1 of my files. I had to copy and paste all the layers into a new file then test it again and that file worked fine.
So thank you SO much for going through all this for me! I really has my life easier now that I can use CS6 the way I need to and I can take advantage of the new bells and whistles it offers. Thank you!
Copy link to clipboard
Copied
you're welcome
Copy link to clipboard
Copied
Thank you Carlos! I am JS illiterate here, any chance you could adjust the script so it outputs files in a serial 0000 + 1 format?
Copy link to clipboard
Copied
I totally missed this post, are you still around?
Copy link to clipboard
Copied
Just wanted to log-in to say thanks, Carlos!! Helped a great deal!
Copy link to clipboard
Copied
Really a handy script! Thanks for the work!
I wonder why in Illustrator still doesnt allow for save4web function like Photoshop has in its scripting. Photoshop seems to have more advanced functions than illustrator. I really need to embed color profiles on export. But we cant do that with javascript functions we currently have 😞
Copy link to clipboard
Copied
I have this problem with the script...
Error 8: Syntax error.
Copy link to clipboard
Copied
I don't know what this error means, are you on Mac? you need to paste the script in a Plain Text Editor, or use the ESTK that comes with adobe and save the script with a *.jsx extension.
Copy link to clipboard
Copied
Yes, I do it like that... with text editor... and I change the extension after... because the text editor of mac doesn't allow me to save as a .jsx
Copy link to clipboard
Copied
It means that the file was saved out of Text Edit on a Mac which defaults to Rich Text Format; hence the rtf1 at the start of the line. The poster needs to use the Format>Make Plain Text from the Text Edit menu bar and then he will be able to Save As a .jsx file.
Copy link to clipboard
Copied
there he goes then, thanks Larry, all clear now.
Copy link to clipboard
Copied
Thanks again, Carlos!
This script has been awesome.
I know this is years later, but if you by chance happen to see this, is it possible to make each PNG clip to the artboard?
Thank you!
Copy link to clipboard
Copied
Hi All
@blissfulOne - I had the same question about clipping to artboard. In the script, just comment out these two lines (put a double-forward-slash // at the beginning):
showAllLayers();
// var docBounds = document.visibleBounds;
// activeAB.artboardRect = docBounds;
I also wanted to use my (unique) layer names as the file names, so I made this change (commented out the original line with // and used layer.name):
// var file = new File(folder.fsName + '/' +filename+ '-' + i+".png");
var file = new File(folder.fsName + '/' +layer.name+".png");
Hopefully this isn't too complicated, even if you aren't familiar with coding 🙂
Copy link to clipboard
Copied
Here's some code I wrote in Applescript that does the same thing. It saves JPGs, but it could easily be changed to save to any file format.
It will take your layer names and remove unwanted characters and spaces first, then turn them into filenames. For example, "Layer 1 / Zig Zag Texture" would become "Layer1ZigZagTexture"
Then it appends the name of the file to each JPG you save out.
set noChar to {".", "/", ":", " "}
tell application id "com.adobe.illustrator"
activate
tell current document
set pathToContainer to POSIX path of ((file path as string) & "::")
set AppleScript's text item delimiters to "."
set fileName to first text item of (name as string)
set AppleScript's text item delimiters to ""
set c to count of layers
set visible of every layer to false
repeat with i from 1 to c
set visible of layer i to true
set layerName to name of layer i as string
set layerName to my remove_chars(layerName, noChar)
set thisJPGName to fileName & "_" & layerName & ".jpg"
set pathString to pathToContainer & thisJPGName
export to file pathString as JPEG with options {class:JPEG export options, artboard clipping:true, quality:80, horizontal scaling:100, vertical scaling:100}
set visible of layer i to false
end repeat
set visible of layer 1 to true
end tell
end tell
on remove_chars(this_text, searchList)
set c to count of searchList
repeat with i from 1 to c
set AppleScript's text item delimiters to item i in the searchList
set the item_list to every text item of this_text
set AppleScript's text item delimiters to ""
set this_text to the item_list as string
end repeat
return this_text
end remove_chars