Skip to main content
Participating Frequently
April 22, 2010
Answered

Export Illustrator layers to separate Illustrator files?

  • April 22, 2010
  • 7 replies
  • 62005 views

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.

    Correct answer Larry G. Schneider

    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.locked == false) doc.layers.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.visible = true;
                else {
                    doc.layers[i-1].visible = false;
                    doc.layers.visible = true;
                }
                if (doc.layers.locked == false) {   
                    docName = realDocName+doc.layers.name+".ai";   
                    var saveName = new File ( doc.path + "/" + docName );
                    doc.saveAs( saveName, saveOpts );
                }
            }
            doc.close(SaveOptions.DONOTSAVECHANGES);
            doc = null;
            app.open (fullDocName);
        }

    /////////End

    7 replies

    Participating Frequently
    March 23, 2017

    Does anyone know of a way to export the selected layers to separate .ai file? I have a layered .ai file and I need to export only selected layers in separate files and would love to avoid ctrl-c ctrl-v to a new file, however, each layer .Thanks in advance.

    Monika Gause
    Community Expert
    Community Expert
    March 23, 2017

    fabio3093  schrieb

    Does anyone know of a way to export the selected layers to separate .ai file? I have a layered .ai file and I need to export only selected layers in separate files and would love to avoid ctrl-c ctrl-v to a new file, however, each layer .Thanks in advance.

    This thread looks like it covers CS4. Or maybe CS6. Or maybe CC? Which is your version?

    Participating Frequently
    March 24, 2017

    i use the CC version

    Participating Frequently
    December 20, 2016

    Opps this is gud. But artboards are not been deleted it is available in all the ai files.

    kolozsih19458695
    Participant
    June 13, 2016

    Try this script: Layer Export

    This is the only one that worked for me

    Participant
    April 14, 2012

    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

    Community Expert
    June 8, 2010

    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 ; )

    Community Expert
    June 7, 2010

    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 )

    Participant
    June 8, 2010

    Not sure. Sorry.

    Why not export everything and just delete the empty files?

    Larry G. Schneider
    Community Expert
    Larry G. SchneiderCommunity ExpertCorrect answer
    Community Expert
    April 22, 2010

    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.locked == false) doc.layers.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.visible = true;
                else {
                    doc.layers[i-1].visible = false;
                    doc.layers.visible = true;
                }
                if (doc.layers.locked == false) {   
                    docName = realDocName+doc.layers.name+".ai";   
                    var saveName = new File ( doc.path + "/" + docName );
                    doc.saveAs( saveName, saveOpts );
                }
            }
            doc.close(SaveOptions.DONOTSAVECHANGES);
            doc = null;
            app.open (fullDocName);
        }

    /////////End

    Art&LogikAuthor
    Participating Frequently
    April 23, 2010

    Actually, I just discovered that the resulting files still had all of the original layers in it. Is there code to delete the non-visible layers and retain only the visible one?

    Thanks for any help.

    Participant
    May 15, 2012

    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


    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..

    and this is the error it gives.

    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!!!!!