Highlighted

Export Illustrator layers to separate Illustrator files?

Community Beginner ,
Apr 22, 2010

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by Larry G. Schneider | Adobe Community Professional

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

Views

50.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Export Illustrator layers to separate Illustrator files?

Community Beginner ,
Apr 22, 2010

Copy link to clipboard

Copied

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.

Adobe Community Professional
Correct answer by Larry G. Schneider | Adobe Community Professional

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

Views

50.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 22, 2010 1
Adobe Community Professional ,
Apr 22, 2010

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 22, 2010 2
Community Beginner ,
Apr 23, 2010

Copy link to clipboard

Copied

That worked great. Thank you so much. The only tweak I made was to eliminate the "realDocName+" from the "docName=" line so that the exported file name was unique to the layer name and not a composite of the target file and resulting file.

The Larry G. Schneider Fan Club is being launched as I type.

Danke.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2010 1
Engaged ,
Mar 24, 2017

Copy link to clipboard

Copied

Art&Logik wrote: "The Larry G. Schneider Fan Club is being launched as I type."

     Sign me up!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 24, 2017 0
Community Beginner ,
Apr 23, 2010

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2010 0
Adobe Community Professional ,
Apr 23, 2010

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2010 0
Community Beginner ,
Apr 23, 2010

Copy link to clipboard

Copied

Mac. Mucho Gracias.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2010 0
Adobe Community Professional ,
Apr 23, 2010

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2010 1
Community Beginner ,
Apr 23, 2010

Copy link to clipboard

Copied

Again, my thanks. I'll give 'er a go.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 23, 2010 0
New Here ,
Jun 05, 2010

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 05, 2010 0
Community Beginner ,
Jun 05, 2010

Copy link to clipboard

Copied

I couldn't get a script to work, so I recorded an action to flatten the layers and batch processed the files. Worked great. Good luck.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 05, 2010 0
New Here ,
May 15, 2012

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2012 0
Adobe Community Professional ,
May 15, 2012

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2012 0
New Here ,
May 15, 2012

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2012 0
Adobe Community Professional ,
May 15, 2012

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 15, 2012 0
Explorer ,
Jan 18, 2013

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 18, 2013 0
New Here ,
Sep 03, 2010

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 03, 2010 0
Community Beginner ,
Oct 12, 2011

Copy link to clipboard

Copied

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)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 12, 2011 0
LEGEND ,
Oct 15, 2011

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2011 1
New Here ,
Jun 02, 2020

Copy link to clipboard

Copied

Hello Larry. I'm attempting to use this script in AICC2020 and getting the below error. Looks like this script is 10 years old. Any idea if it should still work or what might be causing my error? Thanks!

6F00C3FA-9B2A-4103-84BF-6B585EA1238E.jpeg

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 02, 2020 0
Adobe Community Professional ,
Jun 04, 2020

Copy link to clipboard

Copied

Hi,

It may possible while switching old threads to new forum, some of the code get corrupted.  Here is the correct version of the script

 

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

 Let us know if this works for you.

 

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 04, 2020 2
New Here ,
Jun 11, 2020

Copy link to clipboard

Copied

This script resolved the error I was having and now works. Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2020 1
New Here ,
Sep 09, 2020

Copy link to clipboard

Copied

Hi, Charu I ran the script but I don't know where the files are saving? 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2020 0
Adobe Community Professional ,
Sep 09, 2020

Copy link to clipboard

Copied

Hi,

The files are storing at the same location where your ai file is stored. For an example: If you store your AI file at your desktop, then all files created by above script will also store at the desktop.

Best regards

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2020 0
Explorer ,
Jun 07, 2010

Copy link to clipboard

Copied

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 )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2010 0
New Here ,
Jun 07, 2010

Copy link to clipboard

Copied

Not sure. Sorry.

Why not export everything and just delete the empty files?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2010 0
Explorer ,
Jun 08, 2010

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 08, 2010 0
Community Beginner ,
Apr 14, 2012

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 14, 2012 0
New Here ,
Jun 13, 2016

Copy link to clipboard

Copied

Try this script: Layer Export

This is the only one that worked for me

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2016 0
Resources