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

Multiple artboards to multiple layers

Community Beginner ,
Feb 28, 2017 Feb 28, 2017

Copy link to clipboard

Copied

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

Views

4.6K

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

 

       

...

Votes

Translate

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

yeah right, that's what I mean

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

wow thank you so much

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

Copy link to clipboard

Copied

No problem. hope it helps.

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

Copy link to clipboard

Copied

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!

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

Copy link to clipboard

Copied

try copying the script again, I just fixed the error on William's 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 ,
Dec 18, 2021 Dec 18, 2021

Copy link to clipboard

Copied

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!

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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 🙂

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

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

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!

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

Thank you so much! This script is awesome.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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!

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

Copy link to clipboard

Copied

I got an error using this script. 😞

Error 1302 : No such element line

ab.name = doc.layers.name;

 

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

Copy link to clipboard

Copied

I mean to the first script -- making artboards from layers. 

 

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

Copy link to clipboard

Copied

try copy/pasting the script again, I just fixed the indexes of the script posted by azisher

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