6 Replies Latest reply on Oct 29, 2013 9:14 PM by Jux

    Move layers to new artboard

    oxyde68 Level 1

      Hi everybody,


      I'm trying to create a script via javascript for Illustrator.


      My problem is :

      I have a AI file with multiple layers, i want to create one artboard per layer, in order to export a multipage PDF ( each page contain 1 layer ).


      The layers represents the differents type of print ( vernish, color, hot gold, pressure ... ) and/or color type ( Pantone, CMYK, cut, kisscut ... ).

      My client want a PDF for see each type of print or color type per page.


      I'm trying 2 ways :


      1st solution : Create new artboards, and duplicate ( or move ) layers content on the new artboad, but the function move/duplicate don't work to move content on another artboard.


      2nd solution : Create new document with the same number of layers as artboard and duplicate layer to the new artboard on the new document.


      Can you help me to realize this script ?


      Excuse me if my english is not good.

        • 1. Re: Move layers to new artboard
          Muppet Mark Level 5

          You will need to loop the layers and use translate() to move all the page items of each layer to a new x,y location that tallys up with new artboard rectangle…

          • 2. Re: Move layers to new artboard
            ykhatri Level 1

            A very simple implementation for same can be as following:


            var myDoc = app.activeDocument;

            var count = myDoc.layers.length;


            var i=0;

            for(i=0;i<(count-1); i++)


                myDoc.artboards.add ([i*i+10,i*i+10,612,-792]);

                myDoc.rearrangeArtboards (DocumentArtboardLayout.GridByRow,5,20,false);




            for(i=0;i<count; i++)


                    myDoc.layers[i].hasSelectedArtwork = true;

                    myDoc.artboards.setActiveArtboardIndex (i);

                    myDoc.fitArtboardToSelectedArt (i);

                    myDoc.layers[i].hasSelectedArtwork = false;



            You may use this script to explore further and implement the script the way you want it to be. Hope this information helps.

            1 person found this helpful
            • 3. Re: Move layers to new artboard
              oxyde68 Level 1

              Thanks a lot, i'm going to try as soon as possible and i'll give you my feedback about the final script.


              Your two answers has been very useful for my actual and next work !

              • 4. Re: Move layers to new artboard
                oxyde68 Level 1

                I just test your script, it work good but not in my situation.


                In my case all the layers items are superposed and the layer[0] must be present on all the wiev ( because it's the TECHNICAL INFOS layer, with client name, date, ID ... and so ).


                I think i must group items on layer[0], duplicate the new group and translate this group with the layer[1] ( for example ) outside the artboards[0] and after only i can fit artboard to selected art ... is it a good method ?


                See the attached picture, it's a simple draw to understand how the script works ... I hope it will be easier to understand


                Thanks !Script.jpg

                • 5. Re: Move layers to new artboard
                  oxyde68 Level 1

                  Thanks all for your precious advice !

                  Finally, i use this process :

                  1/ Calculate size of artboard, and create the same number of artboard than layers ( with a space between ).

                  2/ I move ( with translate(x,y) ) each items of layers.

                  3/ I duplicate the first layer in a group ( as a reminder, the first layer must appear on all artboards ) and move the new items group on each layers

                  4/ I save the file in PDF.


                  If the source file have a lot of layers, the new artboards exceed the maximum area, but it's not a problem in my case, i want a PDF output only.


                  This is a part of my source code.

                  If you see a part to improve not hesitate to take me back.



                  // Creation of duplicated items ( layer0 must be on all the artboards )
                  var targetLayer = MyDoc.groupItems.add();
                  targetLayer.name = MyDoc.layers[0].name;
                  {   var sourcePageRef = MyDoc.layers[0].pageItems[i];
                      dupRef = sourcePageRef.duplicate();
                      dupRef.moveToBeginning (targetLayer);
                  // Artboards creation
                      var kk = k-1;
                      var kkk = kk-1;
                  var NewArtboardLargeur = (LargeurArtboard+TailleArtboard[0]+offset)*kk;
                  var NewArtboardLargeurFin = NewArtboardLargeur+LargeurArtboard;
                  MyDoc.artboards.add( [NewArtboardLargeur, TailleArtboard[1], NewArtboardLargeurFin, TailleArtboard[3]] ); // création artboard
                      // Déplacement des éléments dans chaque Artboards
                      var ItemsLayer = MyDoc.layers[kk].pageItems.length;
                      { var displacementX = NewArtboardLargeur;
                  // Move layer0 new groups
                  // Save PDF with dialog box for choose the destination folder
                  var destFolder = Folder.selectDialog('Sélection du fichier de destination:');
                  if (destFolder) {
                            var destFile = new File(destFolder+'/'+nomFichier[0]+'-'+timestamp+'.pdf');
                            var pdfSaveOptions = new PDFSaveOptions();
                            pdfSaveOptions.viewAfterSaving = true;
                       pdfSaveOptions.acrobatLayers = true;
                            MyDoc.saveAs (destFile,  pdfSaveOptions); 
                  • 6. Re: Move layers to new artboard
                    Jux Level 1

                    Hi all - curious to know if this is available in a .jsx format ready to go to be used as a script in Illy? In particular, the one that allows for layers to be exported to a brand new artboard. A provided GUI to select layer types and export options would be great.


                    My usecase is that I create UI Kits by either copying/pasting symbols or objects from multiple artboards into one. It would be great if we could just select the layers we wanted and exported them automatically to a new artboard, in a new file.