• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Export Illustrator layers to separate Illustrator files?

Community Beginner ,
Apr 22, 2010 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.

Views

57.3K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 22, 2010 Apr 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.embedLin

...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 22, 2010 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

Votes

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
community guidelines
Community Beginner ,
Apr 23, 2010 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.

Votes

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
community guidelines
Engaged ,
Mar 24, 2017 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!

Votes

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
community guidelines
Community Beginner ,
Apr 23, 2010 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.

Votes

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
community guidelines
Community Expert ,
Apr 23, 2010 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.

Votes

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
community guidelines
Community Beginner ,
Apr 23, 2010 Apr 23, 2010

Copy link to clipboard

Copied

Mac. Mucho Gracias.

Votes

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
community guidelines
Community Expert ,
Apr 23, 2010 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

Votes

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
community guidelines
Community Beginner ,
Apr 23, 2010 Apr 23, 2010

Copy link to clipboard

Copied

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

Votes

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
community guidelines
New Here ,
Jun 05, 2010 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!

Votes

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
community guidelines
Community Beginner ,
Jun 05, 2010 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.

Votes

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
community guidelines
Explorer ,
Jan 18, 2013 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.

Votes

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
community guidelines
New Here ,
May 15, 2012 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!!!!!

Votes

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
community guidelines
Community Expert ,
May 15, 2012 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).

Votes

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
community guidelines
New Here ,
May 15, 2012 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

Votes

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
community guidelines
Community Expert ,
May 15, 2012 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.

Votes

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
community guidelines
New Here ,
Sep 03, 2010 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

Votes

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
community guidelines
Community Beginner ,
Oct 12, 2011 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)

Votes

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
community guidelines
LEGEND ,
Oct 15, 2011 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

Votes

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
community guidelines
New Here ,
Jun 02, 2020 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

Votes

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
community guidelines
Community Expert ,
Jun 04, 2020 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

Votes

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
community guidelines
New Here ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
New Here ,
Sep 09, 2020 Sep 09, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Sep 09, 2020 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

Votes

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
community guidelines
New Here ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

Hi, I'm trying this script on Ai2021 to save a character's elements for animation, it runs alright saving a file for each layer but only the top layer's exported file has visible contents, every other file has them all hidden... not sure if I'm doing something wrong (all my document layers are visible and unlocked)

Votes

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
community guidelines