5 Replies Latest reply on Oct 14, 2018 6:20 AM by Colin Flashman

    Pages to Layers Script

    ixladxi Level 1

      Hello,

      Background: The job I'm working on was created using datamerge. Its a postcard that has a common master page background. I merged in an address and map.

       

      As expected I now have over 200 pages of postcards with the merged background, address, and map. I need to export them into separate files that have individual names. So what I would like to do is somehow move the pages into layers on a single page and name the layers the file names I need, then export them using the script, "PageExporterUtility". For those not familiar PageExporter lets you choose a base layer and variable data layers on top and creates and individual file for each using the name of that layer.

       

      The problem I'm running into is that I can't find a way to move all of the pages into layers on one page.  I found was able to make each page it's own layer but it stays on that page. Here's my script so far below.

       

      Thanks for your help.

       

      Jeff

       

      for(var p=0; p<document.pages.length; p++) 

          var myPageItems = document.pages[p].pageItems.everyItem().getElements(); 

          var myLayerPage = (p+1); 

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

          { 

              try{var myLayer = app.activeDocument.layers.add ({name: "Page " + myLayerPage});}catch(e){}         

              myPageItems[i].itemLayer = "Page " + myLayerPage; 

          } 

      }

        • 1. Re: Pages to Layers Script
          ixladxi Level 1

          I guess I should mention that this is for 2018 CC.

          • 2. Re: Pages to Layers Script
            Benreyn Level 1

            Hi ixladxi,

             

            You were very close... I used your script above and edited as such, notice the last part (added var doc for my script execution purposes):

             

            var doc = app.activeDocument;

             

            for(var p=0; p<document.pages.length; p++)  {

             

                var myPageItems = document.pages[p].pageItems.everyItem().getElements();

                var myLayerPage = (p+1);

             

                for(var i=0; i < myPageItems.length; i++) {

             

                    try {

                        var myLayer = app.activeDocument.layers.add ({name: "Page " + myLayerPage});          

                    } catch(e) {}        

             

                    myPageItems[i].itemLayer = "Page " + myLayerPage;

             

                }

             

            }

             

            var myPage = doc.pages.add();

             

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

                doc.layers[x].pageItems.everyItem().duplicate(myPage);

            }

             

            It will add a page at the end of the document and duplicate all the created layers to it.

             

            Hope that helps.

            1 person found this helpful
            • 3. Re: Pages to Layers Script
              ixladxi Level 1

              Thank you so much! This worked. It combines it all on the last page.

              • 4. Re: Pages to Layers Script
                RichardChenoweth Level 1

                Benreyn This works very well! I have some before and after steps that I would like to add in order to automate a portion of my workflow. I'm more familiar with AppleScript than .jsx and believe I will need to jump from Excel to BBedit to InDesign to accomplish what I'm envisioning.

                My process will be extracting 2 columns of tabbed data, cleaning spaces & line endings, InDesign Data Merge, this script, and moving the resulting layers to the working document.

                 

                I want to take a shot at doing it myself but would greatly appreciate your thoughts and or warnings if any.

                 

                Thanks!

                • 5. Re: Pages to Layers Script
                  Colin Flashman Adobe Community Professional

                  If you still had access to the original un-merged INDD file, would my Data Merge to Unique Names script be of use? Here's a video of it in action: Episode 1: Data Merge to Unique Names - InDesign Javascript by Colecandoo - YouTube