4 Replies Latest reply on Apr 8, 2013 11:55 PM by Muthuraj Durairaj

    find and remove text frames with same geometricBounds

    foredit

      Hi Scripter ...new question starting from here:

       

      var mySelection = app.activeDocument.selection[0].geometricBounds;

      //alert (mySelection);

       

      everywhere in the document i need to find and remove text frames with the same geometricBounds.

      If possible, same dimensions but not same positions.

       

      Thanks for help!

        • 1. Re: find and remove text frames with same geometricBounds
          R-Bala-Krishnan Level 2

          Hi,

           

          According to my understanding, frame which having the equal widthxheight need to be remove, sorry if it’s not match your requirement.

           

          ============================

           

          var mySelection = app.activeDocument.selection[0].geometricBounds;

          var myWidth = Number(mySelection[3]-mySelection[1]);

          var myHeight = Number(mySelection[2]-mySelection[0]);

          var allFrames = app.activeDocument.allPageItems;

          while(t = allFrames.pop() ) {

              if(t.isValid){                     

                  var myTextframe = t.geometricBounds;

                  var myTWidth = Number(myTextframe[3]-myTextframe[1]);

                  var myTHeight = Number(myTextframe[2]-myTextframe[0]);       

                  if((myWidth == myTWidth) && (myHeight == myTHeight)){               

                      t.remove();

                      }

                  }

              }

           

          ===================

          Regards,

          Bala

          • 2. Re: find and remove text frames with same geometricBounds
            foredit Level 1

            Thanks Bala, this is exactly what i mean ...but testing the script (indesign cs6) something is going wrong.

            Not all frames (with same dimensions) are removed.

            Have a better situation using "parseInt" instead of "Number".

            I would join my indesign test document but don't know how.

             

            Anyway, this is great for me, good to work around

            best regards

            • 3. Re: find and remove text frames with same geometricBounds
              foredit Level 1

              ok Bala ...due to decimal differences some frames weren't removed.

              I solved with "Math.round" in place of "Number"

               

              ===================

               

              var mySelection = app.activeDocument.selection[0].geometricBounds;

              var myWidth = Math.round(mySelection[3]-mySelection[1]);

              var myHeight = Math.round(mySelection[2]-mySelection[0]); alert(myHeight);

              var allFrames = app.activeDocument.allPageItems;

              while(t = allFrames.pop() ) {

                  if(t.isValid){                    

                      var myTextframe = t.geometricBounds;

                      var myTWidth = Math.round(myTextframe[3]-myTextframe[1]);

                      var myTHeight = Math.round(myTextframe[2]-myTextframe[0]);      

                      if((myWidth == myTWidth) && (myHeight == myTHeight)){              

                          t.remove();

                          }

                      }

                  }

               

              ===================

               

              Now your script works fine!

               

              Thanks a lot!

              • 4. Re: find and remove text frames with same geometricBounds
                Muthuraj Durairaj Level 1

                Hi,

                 

                I am trying to find and move text frames from one position to another. Below is the code I tried. I am using Indesign CS6, and nothing happened when this script was running. Can you please help me on this. Thanks.

                 

                var oldposition = [216.425, 103.89] // original position, upper left corner

                var newposition = [216.425, 54] // new position, upper left corner

                //var threshold = new UnitValue(1,"pt"); // threshold value

                 

                var myFrame = app.activeDocument.textFrames.everyItem().getElements();

                 

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

                //    if (Math.abs(myFrame[i].geometricBounds[1]-oldposition[0])<threshold &&Math.abs(myFrame[i].geometricBounds[0]-oldposition[1])<threshold ){

                if (Math.round(myFrame[i].geometricBounds[1])==oldposition[0]&&Math.round(myFrame[i].geometr icBounds[0])==oldposition[1]){

                    myFrame[i].move(newposition);

                    }

                }