8 Replies Latest reply on Jan 31, 2011 5:09 AM by Waldviertler

    delete textframes on every page, depending on it's size

    Waldviertler

      Hello!

       

      I've got an catalogue to change, with 500 pages that contains on every page a textframe on the same position with the same size.

      I want to delete this paricular textframe on every page.

       

      How can I start ?

       

      Many thanks for help

       

      Regards

      Martin

        • 1. Re: delete textframes on every page, depending on it's size
          Harbs. Level 6

          Loop through the text frames and check their geometricBounds. If the bounds fit the frame location remove() the frame...

           

          (Include the inner loop inside an outer loop which loops through all pages in the doc...)

           

          Harbs

          • 2. Re: delete textframes on every page, depending on it's size
            Waldviertler Level 1

            Hello Harbs.

             

            I got this part of code, but it does not work.

             

            var doc = app.activeDocument; 
             
            var tFrames = doc.pages[0].textFrames; 
             
            for (var n = tFrames.length-1; n >= 0 ; n--) { 
                 
                var gb = tFrames[n].geometricBounds; 
                var w = gb[3]-gb[1];     
                var h = gb[2]-gb[0];     
                 
                if (h == 20 && w == 20){  
                    tFrames[n].remove(); 
                } 
            }
            

             

            Can you imagine, what is wrong?

             

            /Edit: the size is in mm ----> could that be the mistake?

             

            Thanks

            Martin

            • 3. Re: delete textframes on every page, depending on it's size
              Harbs. Level 6

              Two things:

               

              1) Yes. Make sure your measurement units are correct.

              2) Due to rounding errors do not check for exact values.

               

              try something like this:

               

              if (h > 19 && h < 21 && w > 19 && w < 21){  
                      tFrames[n].remove();
                  }

               

              Harbs

              1 person found this helpful
              • 4. Re: delete textframes on every page, depending on it's size
                Waldviertler Level 1

                Ok, I got it to work:

                 

                var doc = app.activeDocument; 
                doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                var tFrames = doc.pages[0].textFrames;  
                for (var n = tFrames.length-1; n >= 0 ; n--)
                 {          
                      var gb = tFrames[n].geometricBounds;     
                     var w = gb[3]-gb[1];        
                     var h = gb[2]-gb[0];             
                     if (h == 20  && w == 20 )
                     {          tFrames[n].remove();     }
                     } 
                
                

                 

                 

                Now I have to look how to loop through pages.

                 

                thx.

                Martin

                • 5. Re: delete textframes on every page, depending on it's size
                  Harbs. Level 6

                  Keep in mind what I wrote about rounding errors, but here's the idea:

                   

                  function removePageFrames(page){
                    var tFrames = page.textFrames; 
                    for (var n = tFrames.length-1; n >= 0 ; n--){         
                      var gb = tFrames[n].geometricBounds;
                      var w = gb[3]-gb[1];       
                      var h = gb[2]-gb[0];            
                      if (h == 20  && w == 20 ){
                        tFrames[n].remove();
                      }
                    }
                  }
                  for(var i=0;i<doc.pages.length;i++){
                   
                  removePageFrames(doc.pages[i]);
                  }
                  • 6. Re: delete textframes on every page, depending on it's size
                    Waldviertler Level 1

                    A Big Thank You! Harbs.

                     

                    This works:

                     

                    var doc = app.activeDocument; 
                    doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
                    doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                    doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
                    function removePageFrames(page){
                      var tFrames = page.textFrames;  
                      for (var n = tFrames.length-1; n >= 0 ; n--){          
                        var gb = tFrames[n].geometricBounds;
                        var w = gb[3]-gb[1];        
                        var h = gb[2]-gb[0];             
                       if (h > 19 && h < 21 && w > 19 && w < 21){  
                            tFrames[n].remove(); 
                        } 
                      }
                    }
                    for(var i=0;i<doc.pages.length;i++){
                      removePageFrames(doc.pages[i]);
                    }
                    

                     

                     

                    regards

                    Martin

                    • 7. Re: delete textframes on every page, depending on it's size
                      Marijan Tompa [tomaxxi] Level 4

                      I wrote short function to check if the number is between two numbers:

                       

                      Number.prototype.between = function(first,last){
                          if(this >= first && this <= last)
                              return true;
                          else
                              return false;
                      }
                      

                       

                      And simply use:

                       

                      var myNum = 315;
                      
                      if(myNum.between(300,320)){
                        //if true
                      }else{
                        //if false
                      }
                      

                       

                      I just missed Between function from MySQL

                       

                      --

                      tomaxxi

                      http://indisnip.wordpress.com/

                      http://inditip.wordpress.com/

                      • 8. Re: delete textframes on every page, depending on it's size
                        Harbs. Level 6

                        Hi Marijan,

                         

                        You probably know that I'm not into prototype functions, but just for the heck of it, you can make that function a bit shorter:

                         

                        Number.prototype.between = function(first,last){
                            return (this >= first && this <= last);
                        }
                        
                        

                         

                        Harbs