12 Replies Latest reply: Jun 1, 2012 4:57 AM by maxr2012 RSS

    How to move layers to separate pages

    maxr2012 Community Member

      I have an Indesign CS5.5 document with one page and multiple artworks on separate layers. I need to move each layer to a separate page and then to separate documents.

      Is there any quick way of doing this, or script that has been written?

      Thanks, in advance.

        • 1. Re: How to move layers to separate pages
          Laubender CommunityMVP

          @ maxrus2012 – layers are document properties, NOT page properties. So you cannot move a layer to a different page.
          Instead what I guess you want is that you like to move all page items on page one of a specific layer to a different page.

           

          The following script will duplicate all page items per layer to new pages in the same document. You can undo the script.

           

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
          
          app.doScript(_DistributeAllPageItemsOnCurrentPageToNewPages, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Distribute all page items on current page to new pages");
          
          function _DistributeAllPageItemsOnCurrentPageToNewPages(){
          
          var d = app.documents[0];
          var allLayers = d.layers;
          
          allLayers.everyItem().visible = true;
          allLayers.everyItem().locked = false;
          
          for(var n=0;n<allLayers.length;n++){
          
              if(allLayers[n].pageItems.length>0){
                  var pageItemsOnLayer = allLayers[n].pageItems.everyItem();
                  //Unlock every page item on the layer:
                  pageItemsOnLayer.locked = false;
                  //Make all page items visible on the layer:
                  pageItemsOnLayer.visible = true;
                  var myGroup = d.groups.add(pageItemsOnLayer);
                  var newPage = d.pages.add();
                  var myDupOfGroup = myGroup.duplicate(newPage);
                  myDupOfGroup.ungroup();
                  myGroup.ungroup();
                  };
          
              };
          
          }; //END function "_DistributeAllContentsOnCurrentPageToNewPages()"
          

           

           

          Uwe

           

          Message was edited by: Laubender Used advanced editor get syntax highlighting after posting

          • 2. Re: How to move layers to separate pages
            maxr2012 Community Member

            Thanks Laubender,

            I tried to run the script but got the following error message:

            Screen Shot 2012-06-01 at 7.23.27 PM.png

            Can you help out with this, I am running Indesign CS5.5 would that be an issue?

            Cheers,

            Max

            • 3. Re: How to move layers to separate pages
              Laubender CommunityMVP

              @Max – can you provide a simple example of your source document, exported as IDML, that I can download?

               

              Uwe

              • 4. Re: How to move layers to separate pages
                [Jongware] CommunityMVP

                .. or change the script slightly, so it zooms in on the actual error line.

                 

                Put comment slashes before the line that starts with app.doScript:

                 

                // app.doScript ..
                

                 

                so it will be ignored, and add this line

                 

                _DistributeAllPageItemsOnCurrentPageToNewPages();
                

                 

                directly below it. Then re-run and see what it tells you.

                 

                (The doScript construction allows an easy One Step Undo of the entire script, but unfortunately it has the side effect that any errors "inside" the script will be reported as an error from the command that executed the script. Calling the function directly will hopefully show where it fails inside the function.)

                 

                Message was edited by: [Jongware] Gosh, still no way of adding Syntax Hi-lite without post-editing. "Knock knock, anyone there?"

                • 5. Re: How to move layers to separate pages
                  Green4ever Community Member

                  Hi Jongware,

                   

                  OT: The only way is to go to "Use advance editor"....

                   

                  Green4ever

                  • 6. Re: How to move layers to separate pages
                    maxr2012 Community Member

                    Hi Laubender,

                    I don't know how to post a file for you to download and don't have a real file to hand.

                    I have attached a screengrab to illustrate though, which shows a Document with layer and page panels visible.

                    The real document has complex artwork with a full execution of artwork on each layer.

                    So instead of using separate pages for each artwork they used separate layers.

                    I hope this helps you understand the problem better.

                    There is not one document for me to process but many and it will be recurring.

                    Thanks,

                    Max

                    Screen Shot 2012-06-01 at 7.52.44 PM.png

                    • 7. Re: How to move layers to separate pages
                      maxr2012 Community Member

                      Hi Jongware,

                      Thanks, for getting ivolved.

                      I have tried your suggestion and received the following error.

                      Does this narrow it down at all.

                      Thanks,

                      MaxScreen Shot 2012-06-01 at 7.49.45 PM.png

                      • 8. Re: How to move layers to separate pages
                        Green4ever Community Member

                        groups.add([Array of pageItems is Expected Here]);

                         

                        In your example only one page item is present so it throws an invalid parameter error.

                        • 9. Re: How to move layers to separate pages
                          Laubender CommunityMVP

                          @Max – ok. I think I made the mistake to assume that there are more than one page items on a single layer. If there is only one page item, my script will fail because I cannot make a group object out of one single page item.

                           

                          But we can correct that, if we ommit the grouping if there is only one page item in the layer:

                           

                          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                          
                          app.doScript(_DistributeAllPageItemsOnCurrentPageToNewPages, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, "Distribute all page items on current page to new pages");
                          
                          function _DistributeAllPageItemsOnCurrentPageToNewPages(){
                          
                          var d = app.documents[0];
                          var allLayers = d.layers;
                          
                          allLayers.everyItem().visible = true;
                          allLayers.everyItem().locked = false;
                          
                          for(var n=0;n<allLayers.length;n++){
                          
                              if(allLayers[n].pageItems.length>1){
                                  var pageItemsOnLayer = allLayers[n].pageItems.everyItem();
                                  //Unlock every page item on the layer:
                                  pageItemsOnLayer.locked = false;
                                  //Make all page items visible on the layer:
                                  pageItemsOnLayer.visible = true;
                                  var myGroup = d.groups.add(pageItemsOnLayer);
                                  var newPage = d.pages.add();
                                  var myDupOfGroup = myGroup.duplicate(newPage);
                                  myDupOfGroup.ungroup();
                                  myGroup.ungroup();
                                  };
                          
                              if(allLayers[n].pageItems.length===1){
                                  var myPageItem = allLayers[n].pageItems[0];
                                  myPageItem.locked = false;
                                  myPageItem.visible = true;
                                  var newPage = d.pages.add();
                                  myPageItem.duplicate(newPage);    
                                  };
                          
                              };
                          
                          }; //END function "_DistributeAllContentsOnCurrentPageToNewPages()"
                          

                           

                           

                          Uwe

                           

                          Message was edited by: Laubender Did syntax highlighting by advanced editor

                          • 10. Re: How to move layers to separate pages
                            maxr2012 Community Member

                            Hi Laubender,

                            That works a treat with single or multiple items on the page.

                            I'll give it a run on the real files on Monday.

                            Do you have a solution to the second part which was saving each page to a separate document?

                            Much appreciated.

                            Thanks,

                            Max

                            • 11. Re: How to move layers to separate pages
                              Laubender CommunityMVP

                              @Max

                               

                              For that we need a naming scheme for the different single page documents you want to save.

                              But I fear currently I have no time to implement that.

                               

                              There are several scripts floating around in the web which can do that for you.

                              See for example the following script by Hans Haesler (split document):

                               

                              DokumentAufsplitten_512d.jsx

                               

                              at (Mac version in German):

                              http://www.fachhefte.ch/downloads.php?groupIDX=&orderby=name&sort=ASC&search_query=&itemID X=&begin=&limit=&read_category=16&page=0&downloadIDX=651

                               

                              or (Windows version in German):

                              http://www.fachhefte.ch/downloads.php?groupIDX=&orderby=name&sort=ASC&search_query=&itemID X=&begin=&limit=&read_category=16&page=0&downloadIDX=655

                               

                              In case you do not understand the German settings here is a two-step-guide to your single page documents:

                               

                              1. Check the proper feature for splitting pages (every page should become a document of its own):

                               

                              Step1_DokumentAufsplitten_EveryPageOneSingleDocument.png

                               

                              2. Start page numbering with:

                               

                              Step2_DokumentAufsplitten_StartPageNumber.png

                               

                              If you want every single document in its own directory check: "Artikel-Ordner erzeugen".

                               

                              Uwe

                              • 12. Re: How to move layers to separate pages
                                maxr2012 Community Member

                                That was perfect Thankyou very much.