7 Replies Latest reply on Aug 5, 2011 4:09 AM by Harbs.

    Find Item on Pasteboard

    Mac_06 Level 2

      Hi All,

       

      I am sure it could not be a big deal but I'm not able to figure it out, I have a code that remove pages if there is no any text frame or rectangle found. Now my requirement is to check for page item on pasteboard also and if found do'nt delete that page but I am not able to get the reference of paste board item.

       

      function removeEmptyPages(currentDoc){
          try{
          var thePages = currentDoc.pages;
          for(var i=thePages.length-1; i>=0; i--){
          if(thePages[i].textFrames.length==0 && thePages[i].rectangles.length==0){
              thePages[i].remove();
                  }
              }
          }
          catch(e){};
      }
      


      Mac

        • 1. Re: Find Item on Pasteboard
          Techi Panda

          Hi Mac

           

          I hope this helps, This script will locate pasteboard items

           

           

          myDoc = app.activeDocument;

          myObjs = myDoc.pageItems.everyItem().parent;

          for (j = myObjs.length - 1; j >= 0; j--)

          {

          if (myObjs[j].constructor.name == "Page")

          { continue }

          myDoc.pageItems[j].locked=false;

          myDoc.pageItems[j].remove();

          }

           

           

          Thanks

           

          a r u l

          1 person found this helpful
          • 2. Re: Find Item on Pasteboard
            Mac_06 Level 2

            Many Thanks a r u l, I'll get back to you soon.

             

            Mac

            • 3. Re: Find Item on Pasteboard
              Techi Panda Level 2

              Hi Mac

               

              Thanks if you can kindly mark this question is answered if you feel that answer is helpful!

              • 4. Re: Find Item on Pasteboard
                Mac_06 Level 2

                Sorry...for delay a r u l,

                 

                But your code won't work for me since it looks page items in entire document but my requirement is to loop through all pages in document and check if there is no page item founds in particular page just delete that page but not if any found even at pasteboard also. so i tried your code like below:

                 

                myDoc = app.activeDocument;
                removeEmptyPages (myDoc)
                function removeEmptyPages (currentDoc){
                    
                    var thePages = currentDoc.pages;
                    for(var i=thePages.length-1; i>=0; i--){
                    if(thePages[i].textFrames.length==0 && thePages[i].rectangles.length==0){
                        var myObjs= thePages[i].everyItem().parent
                        if(myObjs.length==0)
                        thePages[i].remove();
                            }
                    }
                }
                

                 

                once again thanks to taking interest in issue

                 

                Mac

                • 5. Re: Find Item on Pasteboard
                  Harbs. Level 6

                  FWIW, here's the function I use (which refers to another couple of helper functions).

                   

                      RemoveEmptyPage = function (page,doublePage){//Deals with spreads with objects.
                          if(doublePage){
                              var nextPage = GetDocFromPageItem(page).pages.item(page.documentOffset+1);
                              if(IsValid(nextPage) && nextPage.pageItems.length == 0){
                                  RemoveEmptyPage(nextPage);
                              } else {
                                  return;
                              }
                          }
                          if (page.pageItems.length==0){
                              if (page.parent.pages.length>1||page.parent.pageItems.length==0){page.remove();}
                              }
                          }
                  
                  

                   

                  the doublePage option ensures that pages are only removed in pairs...

                   

                  Harbs

                  • 6. Re: Find Item on Pasteboard
                    Mac_06 Level 2

                    Thanks for reply Herbs, but this also won't work for me: 'page.parent.pageItems' looks page item on spread but I need to check at left side of paste board incase left page and right side of pasteboard incase right page.

                     

                    I tried to write some thing like this: first I inserted the label "left" to pageitem corresponding to left pasteboard and "right" to right pasteboard.

                     

                    myDoc = app.activeDocument;
                    removeEmptyPages (myDoc)
                    function removeEmptyPages (currentDoc){
                        
                        var thePages = currentDoc.pages;
                        for(var i=thePages.length-1; i>=0; i--){
                        if(thePages[i].textFrames.length==0 && thePages[i].rectangles.length==0){
                            if(!removePsudoCut(thePages[i]))
                            thePages[i].remove();
                                }
                        }
                    }
                    
                    function removePsudoCut(thePage)
                    {
                       var i = thePage.parent.rectangles.length
                        while(i--)
                        {
                            var psudoCut = thePage.parent.rectangles[i]
                            if(thePage.side==PageSideOptions.leftHand && psudoCut.extractLabel("LABEL")=="left")
                                return true;
                            else if(thePage.side==PageSideOptions.rightHand && psudoCut.extractLabel("LABEL")=="right")
                            return true
                            else return false;
                    
                    

                     

                    But incase of left page it works fine but incase of right page it removes the page even if there is page item available on right pasteboard.

                     

                    Mac

                    • 7. Re: Find Item on Pasteboard
                      Harbs. Level 6

                      There's no "side" of pasteboards. items on the pasteboard are on the spread, but not on any page.

                       

                      If you need to do things differently depending on where on the pastebaord the item is, you'll need to loop through all items on the spread and check the visibleBounds against the page bounds.

                       

                      HTH,

                      Harbs