5 Replies Latest reply on Apr 28, 2010 4:07 PM by John.Kordas

    CS3 JS Double Page Spread

    John.Kordas

      I'm trying to see if pages have items on them before sending off the page using:

       

      if(myDocument.pages[myPageName-1].pageItems.length==0){


      }

       

      This works well until I get a double page spread item.  The element sits on the left hand page and extends onto the right hand page but ID only reads the link as being on the left hand page not the right.

       

      Is there a better way to check if pages are blank?

       

      Cheers John.

        • 1. Re: CS3 JS Double Page Spread
          Marc Autret Level 4

          InDesign assumes that a pageItem ‘belongs’ to a page if the geometric bounds of the page contains the center point of the pageItem bounding box. So you can have a pageitem located on page N that overlaps some other pages in the same spread. Actually the most relevant geometric container is the spread. To know if a page is really blank, you can traverse the parent spread page items collection and check if the bounds of one object intersects your target page.

           

          Try this:

           

          Page.prototype.hasPageItems = function()
          {
               var sprd, pItems, b, ib;
               
               // check if the page contains a direct page item
               if( this.pageItems.length > 0 ) return true;
               
               // check if the page intersects a spread page item
               if( (sprd=this.parent).pageItems.length > 0 )
                    {
                    b = this.bounds;
                    pItems = sprd.pageItems;
                    for( i=pItems.length-1 ; i>=0 ; --i )
                         {
                         ib = pItems[i].geometricBounds;
                         if( b[0]<=ib[2] && ib[0]<=b[2] &&
                              b[1]<=ib[3] && ib[1]<=b[3] )
                              return true;
                         }
                    }
               return false;
          }
          
          
          // sample test
          var doc = app.activeDocument;
          alert( doc.pages[2].hasPageItems() );
          

           

          @+

           

          Marc

          - - -

          http://www.indiscripts.com

          1 person found this helpful
          • 2. Re: CS3 JS Double Page Spread
            Laubender Adobe Community Professional & MVP

            Hello Marc,
            your function does not work if the zero point is defined by page or by spine. If the zero point is defined by spread it is working very well.
            (InDesign CS4 6.0.4 on Mac OS X 10.5.8)

             

            Uwe

            • 3. Re: CS3 JS Double Page Spread
              Marc Autret Level 4

              That's right. I just give a snippet for the main routine. In a complete script we often need to deal with user specific settings.

               

              I usually write a backup/restore method to set the preferences as needed during the script execution. Something like:

               

              // backup the settings

              var vPrefs = doc.viewPreferences;

              var bkpOrigin = vPrefs.rulerOrigin;

               

              // set the origin as needed

              vPrefs.rulerOrigin = RulerOrigin.spreadOrigin;

               

              /* THE SCRIPT PROCESS HERE */

               

              // restore the settings

              vPrefs.rulerOrigin = bkpOrigin;

               

              @+

              Marc

              • 4. Re: CS3 JS Double Page Spread
                John.Kordas Level 1

                Thanks Marc,

                 

                This is very interesting.  I have a slight problem as the book I'm testing has full page bleed elements so even pages that do not have elements but have one that is bleeding off to the side come up as true. The bleed is only 5mm but it's enough to pick it up.

                 

                Any suggestions?

                 

                Cheers, John.

                • 5. Re: CS3 JS Double Page Spread
                  John.Kordas Level 1

                  Thanks Marc,

                   

                  I was finding that pages that had bleed on one side of the spread would still be picked up and exported. To get around this all double page spreads are placed on the left had page so to check this I added.

                  myPageName%2 == 1

                  Then I also checked there was an item on the spread using

                  myDocument.pages[myPageName-1].parent.pageItems.length >0

                  Finally I check that the item on the spread is wider than one page.

                  myDocument.pages[myPageName-1].parent.pageItems[0].geometricBounds[3] > (app.activeDocument.documentPreferences.pageWidth + 5)

                   

                  All together:

                  if(myPageName%2 == 1 && myDocument.pages[myPageName-1].parent.pageItems.length >0 && myDocument.pages[myPageName-1].parent.pageItems[0].geometricBounds[3] > (app.activeDocument.documentPreferences.pageWidth + 5)){

                   

                  I was trying to solve this at a page level and when I broke down your code the answer was to work at the spread level instead.

                   

                  Thanks for your example and I also suggest people check out your website.

                   

                  Cheers John.