15 Replies Latest reply on Nov 1, 2016 9:03 AM by Laubender

    Remove Spreads

    Gonterman1201 Level 1

      I'm working on something that I want tor remove spreads and for some reason it is just removing the page. Also it is counting single pages as a spread. I think its weird and I wonder if anyone knows what is up with this.

       

      myDoc = app.activeDocument;

      d=myDoc.filePath+"/"+myDoc.name ;

      myPages = app.activeDocument.spreads;

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

          alert( myPages[i]);

          myPages[i].remove();

      }

        • 1. Re: Remove Spreads
          [Jongware] Most Valuable Participant

          Not an answer, but first off, it looks like you are attempting to remove all pages (or spreads) in a document. That is not going to work.

           

          Second: when removing stuff with a loop, start at the end! That is because when you remove the first spread (or page, or anything else for that matter), the original number 1 shifts up to position 0, and so on until the end of the document. Then you remove #1, and the same happens with original page #2. So essentially, you are skipping a large part of the items.

           

          I am surprised you don't get an error while running the script.

          • 2. Re: Remove Spreads
            Gonterman1201 Level 1

            blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px #715FFA solid !important; padding-left:1ex !important; background-color:white !important; }  It doesn't error because it iterates through spreads and removes single pages

             

             

            Sent from Yahoo Mail for iPhone

            • 3. Re: Remove Spreads
              Laubender Adobe Community Professional & MVP

              Hi Gonterman,

              can you show us a screenshot of the document before the first iteration of the loop and one screenshot after the first iteration of the loop?

               

              What would you expect with the following document:

              1-Before-RemovingFirstSpread.png

               

              if you remove the first spread with:

               

              app.documents[0].spreads[0].remove();
              

               

              Result 1 with a plain facing-pages document:

               

              2-After-RemovingFirstSpread.png

               

              But that result is just a result by default.

              Alternatively the following result is also possible.

               

              Result 2:

               

              3-After-RemovingFirstSpread.png

               

              Two results depending on just one preference:

               

              app.documents[0].documentPreferences.allowPageShuffle
              

               

              If true, see result 1, if false see result 2.

               

              I think, we can answer your question only after seeing more of your document.

               

              Regards,
              Uwe

              • 4. Re: Remove Spreads
                Gonterman1201 Level 1

                If i use app.documents[0].spreads[0].remove();
                it just removes the last page of the book. I really would expect it to remove 6-7.

                Can you explain why this happens?

                • 5. Re: Remove Spreads
                  Gonterman1201 Level 1

                  I'm not worried about going backwards. I just want to split each spread into separate documents. It should not matter which way i go. If i alert what the document spread is I get this which is what i would expect. I also would expect it to be removed but it doesn't.

                  • 6. Re: Remove Spreads
                    Peter Kahrel Adobe Community Professional & MVP

                    > Also it is counting single pages as a spread. I think it's weird

                     

                    Maybe you should show us a screenshot of your Pages panel. Sounds as if you have 1-page spreads.

                     

                    > It doesn't error because it iterates through spreads and removes single pages

                     

                    Again, that sounds like single-page spreads.

                     

                    > I just want to split each spread into separate documents

                     

                    You mean 'I just want to save each spread as a separate document', don't you?

                     

                    Peter

                    • 7. Re: Remove Spreads
                      Gonterman1201 Level 1

                      Yes that is correct. And it is true that it treats these pages as spreads.

                      • 8. Re: Remove Spreads
                        Laubender Adobe Community Professional & MVP

                        Hi Gonterman,
                        what does the allowPageShuffle property of the documentPreferences say?

                         

                        And could you show in detail what's going wrong?


                        Before (screenshot) and after running the first iteration of your for loop (screenshot) of page 1, 2 and 3…
                        Do it not from the Pages Panel but from actual document pages perhaps at a zoom factor of 15 %.

                         

                        Regards,
                        Uwe

                        • 9. Re: Remove Spreads
                          Gonterman1201 Level 1

                          how do I check allowPageShuffle?

                          • 10. Re: Remove Spreads
                            Gonterman1201 Level 1

                            allow page shuffle is true.

                            After deleting what should be a spread object. it deletes the last page. Instead of deleting the whole spread.

                            • 11. Re: Remove Spreads
                              Laubender Adobe Community Professional & MVP

                              Hi Gonterman,

                              can I see the context menu of your Pages Panel where "Allow Page Shuffle" and "Preserve Layout When Shuffeling" can be set?
                              And put some contents on the page before showing, like text frames showing "A" on page 1, "B" on page 2 and "C" on page 3 perhaps.
                              Do not use automatic page numbering for this.


                              Then do two screenshots:

                               

                              1. Before running code

                              2. After running:

                               

                              app.documents[0].spreads[0].remove();
                              

                               

                               

                              Also see (again) my answer #3 above. And some DOM documentation here:

                              Adobe InDesign CS6 (8.0) Object Model JS: DocumentPreference

                               

                              Do two tests. One with allowPageShuffle set to true. And one set to false.

                              Setting that option with the documentPreferences to get the result as shown in my example 2 in answer #3 will be :

                               

                              app.documents[0].documentPreferences.allowPageShuffle = false;
                              

                               

                              Note: This property can be set also with [object Spread]:

                              Adobe InDesign CS6 (8.0) Object Model JS: Spread

                               

                              app.documents[0].spreads.everyItem().allowPageShuffle = false;
                              

                               

                              But then we'll perhaps get a totally different picture.

                               

                              Regards,
                              Uwe

                              • 12. Re: Remove Spreads
                                Gonterman1201 Level 1

                                Okay changing allowPagesShuffle to false;  Worked except my spreads length is 9 so it is counting that first single page as a spread. Also it stopped prematurely. It did half of what it should have done.

                                • 13. Re: Remove Spreads
                                  TᴀW Adobe Community Professional & MVP

                                  How about just keeping it simple?

                                   

                                  s = app.activeDocument.spreads;

                                  s.itemByRange(15, 20).remove();

                                   

                                  Will remove spread 15 through spread 20. Modify as needed.

                                   

                                  Ariel

                                  1 person found this helpful
                                  • 14. Re: Remove Spreads
                                    Gonterman1201 Level 1

                                    Actually I think that might work. Thanks.

                                    • 15. Re: Remove Spreads
                                      Laubender Adobe Community Professional & MVP

                                      Still, I'm not exactly sure what you'd like to accomplish…

                                      Gonterman1201 wrote:

                                      … Worked except my spreads length is 9 so it is counting that first single page as a spread.

                                      A Spread object can contain 1 to 10 pages. Your first spread contains exactly one page. So nothing unusual here. (With older InDesign versions—CC 2014.1 and before—even more than 10, but that's a different story…)

                                       

                                      Ariel is using itemByRange. That together with the right setting for allowPageShuffle should get you going.

                                       

                                      You could also set the startPageNumber of a document in its documentPreferences.

                                      That a page on the left of the spine is named "1" is rather unusual.

                                       

                                      Best regards,
                                      Uwe