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

Multiple artboards to multiple layers

Community Beginner ,
Feb 28, 2017 Feb 28, 2017

Hello everyone, I have this script to convert multiple layers to multiple artboards, and also copy each layer name to artboards.

The problem is how to reserve the this script process?

I mean to converts artboards to layer and copy artboards name to layer. Thanks

 

#target illustrator 

 

main(); 

 

function main() { 

   

          if ( app.documents.length == 0 ) { return; } 

 

          var doc = app.activeDocument; 

   

          doc.layers[0].hasSelectedArtwork = true; 

   

          doc.fitArtboardToSelectedArt( 0 ); 

   

          doc.selection = null; 

 

          for ( var  i = 1; i < doc.layers.length; i++ ) { 

   

                    doc.artboards.add( [0,0,72,-72] ); 

   

                    doc.layers[i].hasSelectedArtwork = true; 

   

                    doc.fitArtboardToSelectedArt( i ); 

   

                    doc.selection = null; 

 

          }; 

 

};

 

if (app.documents.length == 0) {

    alert("No Open / Active Document Found");

} else {

    var doc = app.activeDocument;

    if (doc.artboards.length == doc.layers.length && doc.layers.length == doc.artboards.length) {

        for (var i = 0, l = doc.artboards.length; i < l; i++) {

            var ab = doc.artboards[i];

            ab.name = doc.layers[i].name;

        }

        alert("Finished:\nRenaming of Artboards to match Layer names is complete");

    } else {

        alert("Opps: This wont work!\n The number of Layers and Artboards do not match");

    }

}

TOPICS
Scripting
6.5K
Translate
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 , Mar 01, 2017 Mar 01, 2017

Here you go.

 

function layersFromArtboards()

{

    var docRef = app.activeDocument;

    var layers = docRef.layers;

    var aB = docRef.artboards;

 

    //we will remove this layer after the others have been created.

    var tempLay = layers[0];

    tempLay.name = "Temp";

 

    //loop the artboards

    for(var x=0;x<aB.length;x++)

    {

        var thisAb = aB[x];

        aB.setActiveArtboardIndex(x);

        docRef.selectObjectsOnActiveArtboard();

        var sel = docRef.selection;

 

       

...
Translate
Adobe
Community Expert ,
Feb 28, 2017 Feb 28, 2017

Not sure exactly why yours didn't work, but that code was a little messy. it had multiple tests to determine whether a doc exists, and there are two loops where you could get away with one. Here's a snippet that i briefly tested and is working how you want, unless i misunderstand what you're asking for.

 

function container()

{

  if(app.documents.length > 0)

  {

    var doc = app.activeDocument;

    var layers = doc.layers

    var artboards = doc.artboards;

 

    for(var i=0;i<doc.layers.length;i++)

    {

      if(i>0)

      {

        var newAb = artboards.add([0,0,5,-5]); 

      }

      var thisLayer = doc.layers[i];

      thisLayer.hasSelectedArtwork = true;

      doc.fitArtboardToSelectedArt(i);

      artboards[i].name = layers.name;

      doc.selection = null;

    }

    alert("Finished:\nRenaming of Artboards to match Layer names is complete");

  }

  else

  {

    alert("No Open / Active Document Found");

  }

}

container();

 

 

Screen Shot 2017-02-28 at 2.09.42 PM.jpg

Translate
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 ,
Mar 01, 2017 Mar 01, 2017

Hi William, thank you for your answer, but its not what I want.

I want to reserve the script, from artboards to layers. Artboards >> Layers

Translate
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 ,
Mar 01, 2017 Mar 01, 2017

I think something is getting lost in translation here. I don't believe i'm understanding.

Are you saying that you want to create one layer for each artboard and set the layer name to match the artboard name?

Translate
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 ,
Mar 01, 2017 Mar 01, 2017

yeah right, that's what I mean

Translate
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 ,
Mar 01, 2017 Mar 01, 2017

Ok. the necessary logic changes a lot then. We can't use methods like "layers[0].hasSelectedArtwork = true".

Do you have a sample file you can share so that I can be sure to account for the specifics of your file?

Translate
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 ,
Mar 01, 2017 Mar 01, 2017
Translate
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 ,
Mar 01, 2017 Mar 01, 2017

Here you go.

 

function layersFromArtboards()

{

    var docRef = app.activeDocument;

    var layers = docRef.layers;

    var aB = docRef.artboards;

 

    //we will remove this layer after the others have been created.

    var tempLay = layers[0];

    tempLay.name = "Temp";

 

    //loop the artboards

    for(var x=0;x<aB.length;x++)

    {

        var thisAb = aB[x];

        aB.setActiveArtboardIndex(x);

        docRef.selectObjectsOnActiveArtboard();

        var sel = docRef.selection;

 

        //create a new layer

        var newLay = layers.add();

        newLay.name = thisAb.name;

 

        //loop through the selection and move all artwork onto new layer

        //this is only necessary if the artwork on a given artboard is not

        //grouped. This ensures that all the art will be moved, even if there are

        //multiple ungrouped objects.

        for(var a=0;a<sel.length;a++)

        {

            sel[a].moveToEnd(newLay);

        }

    }

 

    tempLay.remove();

}

layersFromArtboards();

Translate
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 ,
Mar 01, 2017 Mar 01, 2017

wow thank you so much

Translate
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 ,
Mar 01, 2017 Mar 01, 2017

No problem. hope it helps.

Translate
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 ,
Dec 18, 2021 Dec 18, 2021

Hello Dilliam,

I'm running Illustrator 25.4.1 and somehow your script returns me the following error: "Error 24: sel.moveToEnd is not a function".

Is there any change necessary?

Thankks zillions for your precious help!

Translate
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 ,
Dec 18, 2021 Dec 18, 2021

try copying the script again, I just fixed the error on William's script

Translate
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 ,
Dec 18, 2021 Dec 18, 2021

Thanks a bunch Carlos, it works like a charm now!

Actually I was expecting that each created layers would go on the first artboard, and not to stay on their respective ones as it is with William's script. Would you know any way to fix this?

Thanks again for your precious help!

Translate
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 ,
Dec 18, 2021 Dec 18, 2021

Hi, do you have multiple artboards and you want to put all of them on top of each other like pancakes?

Translate
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 ,
Dec 18, 2021 Dec 18, 2021

Yes, exactly. I wish to have all my artboards put on top of each other, in different layers, on a unique artboard. Like pancakes, as you put it so nicely 🙂

Translate
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 ,
Dec 18, 2021 Dec 18, 2021
Translate
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 ,
Dec 18, 2021 Dec 18, 2021

No, it doesn't, or not really. The "AI-merge" script doesn't open PDF files. I tried with AI files (by simply changing the extension of my PDF to .ai) and it worked fine, but even then it puts every document on its own layer (unless, like in the video, the artboard size is too small).

As for the other method, that is to Paste Remembers Layers, I use it regularly but that would involve much manual work. Having a large number of files to process, I wish I could find a script to automatise much of the work.

Once more, thanks zillions for your time!

Translate
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 ,
Dec 18, 2021 Dec 18, 2021

Oops, one should read "but even then it puts every document on its own artboard" (not layer). Furthermore, I just find out that this script is not really precise and the location of each document on artboard varies of some 1 to 2 points (bad idea as my layers have to be very precisely aligned).

Translate
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 ,
Jun 04, 2024 Jun 04, 2024

Thank you so much! This script is awesome.

Translate
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 ,
Apr 08, 2025 Apr 08, 2025

This works really well, but it does appear to create each layer twice, in my case I had 43 artboards, and now I have 86 Layers where half of them are empty and easy to clean up, but I figured I'd mention it.

I'm using Illustrator 2024 for this

Translate
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 ,
Apr 08, 2025 Apr 08, 2025
LATEST

Not sure why I can't edit my comments, but it turns out my script panel is for some reason executing every script twice all of a sudden, so your script wasn't at fault here, my bad

Translate
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 ,
Aug 03, 2017 Aug 03, 2017

Hi Williamadowling

I have used the layers to artboards script which is great and works really well, thank you so much. Is there a way of adding a 20mm edge to the new

Is there a way of adding a 20mm edge to the new artboards?

Thanks again

Translate
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 ,
Aug 03, 2017 Aug 03, 2017

It's a good idea to create a new post for that. It helps keep the forum organized and makes it easier for someone else in the future who has the same question you have.

Translate
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 ,
Aug 03, 2017 Aug 03, 2017

Ok thank you. I actually found a script to add a margin and then ran it as a batch action to all files.

Thanks again for the script!

Translate
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 ,
Sep 10, 2021 Sep 10, 2021

I got an error using this script. 😞

Error 1302 : No such element line

ab.name = doc.layers.name;

 

Translate
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