Skip navigation
Art&Logik
Currently Being Moderated

Export Illustrator layers to separate Illustrator files?

Apr 22, 2010 2:17 PM

Does anyone know of a way within AI CS4 to export layers to separate .ai files? Or third party plug-in to do the same? Preferably retaining the layer name as the new file name.

 

I have a layered .ai file with 40 layers of logo versions that I need to export to separate files and I'd like to avoid the obvious "save as" and delete layers route.

 

Thanks in advance.

 
Replies
  • Currently Being Moderated
    Apr 22, 2010 2:56 PM   in reply to Art&Logik

    Try this. Cut and paste into a text editor and save as a plain text file with a .jsx extension. You can either place it into your AICS4>Presets>Scripts folder and restart AI or just run it from File>Scripts>Other Scripts.

     

    //////////////Start

     

    var doc = app.activeDocument;
       
    if (documents.length > 0){
           
        // Create the illusrtratorSaveOptions object to set the AI options
        var saveOpts = new IllustratorSaveOptions();
       
        // Setting IllustratorSaveOptions properties.
        saveOpts.embedLinkedFiles = true;
        saveOpts.fontSubsetThreshold = 0.0
        saveOpts.pdfCompatible = true

     

           
            if (doc.saved==false) doc.save();
           
            for (i=0; i<doc.layers.length; i++)
                if (doc.layers[i].locked == false) doc.layers[i].visible = false;
            fullDocName = doc.fullName;
            var param = doc.name.split('.');
            realDocName = param[0];
            for (i=0; i<doc.layers.length; i++){
                if (i-1<0) doc.layers[i].visible = true;
                else {
                    doc.layers[i-1].visible = false;
                    doc.layers[i].visible = true;
                }
                if (doc.layers[i].locked == false) {   
                    docName = realDocName+doc.layers[i].name+".ai";   
                    var saveName = new File ( doc.path + "/" + docName );
                    doc.saveAs( saveName, saveOpts );
                }
            }
            doc.close(SaveOptions.DONOTSAVECHANGES);
            doc = null;
            app.open (fullDocName);
        }

     

    /////////End

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 23, 2010 11:35 AM   in reply to Art&Logik

    Are you working on a Mac or a PC? If a Mac I have another script which will do that. I'll need a little while to figure out how to translate it to JS.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 23, 2010 12:46 PM   in reply to Art&Logik

    Since in AI scripting you can't delete a hidden layer, this reverses the visibility of the layers and then deletes the visible layers. It then makes all layers visible and saves the file.

     

    --------Start

     

    --get a sourceFolder that holds the files to process
    set sourceFolder to (choose folder with prompt "Choose a folder with files to process:") as text

     

    -- get a list of files of the files to process in the sourceFolder
    tell application "Finder" to set workingFiles to (every file of folder sourceFolder) as alias list

     


    repeat with aFile in workingFiles
        tell application "Adobe Illustrator"
            open aFile
           
            set currentFile to front document
           
            tell application "Adobe Illustrator"
                set myLayers to every layer of currentFile
               
                repeat with i from 1 to count of items in myLayers
                   
                    set myLayer to item i of myLayers
                    set locked of myLayer to false
                   
                    if visible of myLayer is true then
                        set visible of myLayer to false
                    else if visible of myLayer is false then
                        set visible of myLayer to true
                    end if
                   
                end repeat
               
                delete (every layer of currentFile whose visible is true)
               
            end tell
           
            tell application "Adobe Illustrator"
               
                set visible of (every layer of currentFile) to true
               
            end tell
           
            close currentFile with saving
           
        end tell
    end repeat

     

    --------End

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 5, 2010 2:41 AM   in reply to Art&Logik

    Were you guys ever able to figure out how to delete the hidden layers?

    Is there a way to "flatten the document" with scipt?

     

    I can't get it to work and it's killing me.

     

    Thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2010 4:34 PM   in reply to Art&Logik

    Visible or not. Does anybody know how to export layers with content only and skip those without? (so to say **content aware** for Illustrator ; )

     

    ( if that matters: .js for PC would be great )

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2010 8:24 PM   in reply to nmbdesign

    Not sure. Sorry.

     

    Why not export everything and just delete the empty files?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 8, 2010 3:22 AM   in reply to Art&Logik

    Thats the way I do it right now

     

    But think of five docs a day including 6 or more basic (must have) layers using only 2 or 3 of them frequently depenting on the content.

     

    I once saw a script exporting only layers with content, unfortunatelly I don*t know which it was and where to get it from.

     

    (and I*m curious of course ; )

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 3, 2010 6:34 PM   in reply to Larry G. Schneider

    I never heard of scripts until now.  Are they hard to do?  I was wanting to do exactly what this script did, but instead of saving as to an .ai, I wanted to export as a psd at:

     

    300dpi

    flat image

    anti aliasing checked

    imbed ICC profile UNchecked

     

    Is this possible to do?

     

    If you could do this or show me where to learn that would be awesome.

     

    Thank you thank you thank you.

     

    Justin

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 12, 2011 3:13 PM   in reply to jdutle

    I haven't laughed this hard in quite some time. I no longer get frustrated with Adobe's mysterious choices in arbitrarily blanking fundamental capability. It's just entertaining now. Someone asks for a way to export layers as separate files and gets back a page of code and advice on how to develop scripts? Hysterical!! I've never seen anything so funny. It's going in my next screenplay. By the way, if your mechanic did this to you you'd take her to small claims. (laughter echoes on)

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 15, 2011 4:57 PM   in reply to DevarySS

    if your mechanic did this to you you'd take her to small claims.

    Actually, if my mechanic could fix my vehicle with Javascript, I'd take him to lunch and pick his brain.

     

    JET

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2012 8:08 AM   in reply to Art&Logik

    Holy smoke! This script is just the ticket! Thank you so much. You have saved me hours of work. I'm looking for a way in import individual layers from one Illustrator files into Apple Motion 5, so I can animate each layer independently. Again, thank you!

     

    Tom

     
    |
    Mark as:
  • Currently Being Moderated
    May 15, 2012 1:43 PM   in reply to Larry G. Schneider

    i wasn't able to get the second script to work (the one that should remove the layers that don't belong in the new file).

     

    i don't know much about scripting, but the first file doesn't look anything like the second..

     

    Picture 80.png

     

     

    and this is the error it gives.

    Picture 81.png

     

     

    may i get help on this script to save only the layer information per the new file it's creating?

     

    @tpf1952.. it worked for you?

     

     

    thank you if anyone can help!!!!!

     
    |
    Mark as:
  • Currently Being Moderated
    May 15, 2012 2:03 PM   in reply to polifka

    The script you show in the right hand window is an AppleScript that will only work on a Mac. It should be placed in the Apple Script editor. You've placed it in the ESTK which is only used for ExtendScript (Adobe's implementation of Java Script).

     
    |
    Mark as:
  • Currently Being Moderated
    May 15, 2012 2:29 PM   in reply to Larry G. Schneider

    i'm sorry.  i will be slow to figure this out probably.  lol.  thank you for responding.

     

    i am on a mac.

     

    i opened the apple script program? and it will not allow me to save this file.

     

    Picture 82.png

     
    |
    Mark as:
  • Currently Being Moderated
    May 15, 2012 2:59 PM   in reply to polifka

    Just do the same thing you just did but now hit the Compile button ( the hammer), then try to save.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 18, 2013 11:08 AM   in reply to Art&Logik

    Did you find a way to go around the prompt about discarding hidden layers? I couldn't get rid of this dialog and the action became useless, I still need to click ok each time a document is flattened.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points