2 Replies Latest reply on May 5, 2010 8:23 PM by PankChat

    getting geometric bounds of each textframe of each page

    PankChat Level 1

      Hi all,

      I am trying to get the geometric bounds of each text frame of each page on whole document. Below is the snippet of my script. All seems to be fine earlier but as soon as I did some changes (and why I did) it seems I cannot iterate frames page by page and it stricts to 1st page instead of going on each page. Can anybody tell me what could possibly wrong:

      // Error here var top_Bound = Text_FRAME.geometricBounds[0];

        

        

      var myTotalPage = myDoc.pages.length;

      //alert("Total Pages in current document is " +myTotalPage);

        

      //var pageItems = myDoc.pages[k].allPageItems;

      //alert ("All Page Items is "+ pageItems)

      for (var i=0;i<=myTotalPage;i++)

      {

       

      var totalTextFrames = myDoc.pages[i].textFrames.length;

      //alert ("Total Text Frames on page are "+ totalTextFrames)

        

      for (var t=0;t<=totalTextFrames;t++)

      {

      var Text_FRAME = myDoc.pages[i].textFrames[t];

      //getting error here

      var top_Bound = Text_FRAME.geometricBounds[0];

      var left_Bound = Text_FRAME.geometricBounds[1];

      var bottom_Bound = Text_FRAME.geometricBounds[2];

      var right_Bound = Text_FRAME.geometricBounds[3];

        

      //alert ("My Top Bound is " +top_Bound);

      //alert ("My left Bound is " +left_Bound);

      //alert ("My Bottom Bound is " +bottom_Bound);

      //alert ("My right Bound is " +right_Bound);


      }  
       

      }


      }

        • 1. Re: getting geometric bounds of each textframe of each page
          Techi Panda Level 2

          Hi Pank this will do your work

           

          myDoc= app.activeDocument;

          var myTotalPage = myDoc.pages;

          //alert("Total Pages in current document is " +myTotalPage);


          //var pageItems = myDoc.pages[k].allPageItems;

          //alert ("All Page Items is "+ pageItems)

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

          {

          var totalTextFrames = myDoc.pages[i].textFrames;


          //alert ("Total Text Frames on page are "+ totalTextFrames)


          for (var t=totalTextFrames.length-1; t>=0;t--)

          {

          var Text_FRAME = myDoc.pages[i].textFrames[t];

          //getting error here

          app.selection=myDoc.pages[i].textFrames[t];

          var top_Bound = Text_FRAME.geometricBounds[0];

          var left_Bound = Text_FRAME.geometricBounds[1];

          var bottom_Bound = Text_FRAME.geometricBounds[2];

          var right_Bound = Text_FRAME.geometricBounds[3];


          alert ("My Top Bound is " +top_Bound);

          alert ("My left Bound is " +left_Bound);

          alert ("My Bottom Bound is " +bottom_Bound);

          alert ("My right Bound is " +right_Bound);


          }  

          }

          • 2. Re: getting geometric bounds of each textframe of each page
            PankChat Level 1

            Thanks Arul.

             

            Any Ideas you can share.

             

             

            I think I am stuck in my script. All I am trying to do

            is to find out the position of the textframes on each page and cases are :

             

            1. If any of the text frame lies at the bottom (ideally at the page end) I

             

            need to insert some text (marker) at the end of the story of text frame

            with label "sections" (which is actually is my main non-floating frame).

             

            2. If there is no text frame apart from the "sections" or frames are at

            the bottom of page end insert something else at the end of story of

            "sections" text frame.

             

            well in short I need to add text at the end of the "sections" TF on each

            page while looking at the positions of other (floats) frame. I am just

            worried whether I did it write or should re-write my whole code:I am using

             

            two scripts for this one which splits the story of pages (ideally

            "sections" Threaded textframe) and another one is looks something like

            below. I am stuck in comparing the Geometric bounds of frames with

            "sections" one and I think something I've to do with my loops. Hope I make

             

            myself clear.

             

            Below is snippet what it looks like:

             

            if(app.documents.count==0)

            {

            alert ("Please open a document for PageBreak");

             

            }

             

             

            else

            {

                    var myDoc=app.activeDocument;

             

             

            var myTotalPage = myDoc.pages.length;

             

            alert("Total Pages in current document is " +myTotalPage);

             

             

            //var pageItems = myDoc.pages[k].allPageItems;

             

            //alert ("All Page Items is "+ pageItems)

             

             

            for (var i=0; i<=myTotalPage-1; i++)

             

            {

             

            var totalTextFrames = myDoc.pages[i].textFrames.length;

             

            alert ("Total Text Frames on page " +myDoc.pages[i].name " are "

            totalTextFrames)

             

             

            for (var t=0;t<=totalTextFrames-1;t++)

            {

                                            var Text_FRAME =

            myDoc.pages[i].textFrames[t];

            //                              alert ("Text Frame is "+Text_FRAME);

             

             

            // Is actually

             

                                    if (Text_FRAME.label!="sections")

                                                    {

                                                            alert ("Not sections")

                                                            var bottom_Bound_float =

            Text_FRAME.geometricBounds[2];

                                                            var right_Bound_float =

            Text_FRAME.geometricBounds[3];

                    //                                      alert ("My right Bound of

            Not Sections is " +right_Bound);

                    //                                      alert ("My bottom Bound of

             

            Not Sections is " +bottom_Bound);

                //                                  alert ("My Geometric bounds are "

            +Text_FRAME.geometricBounds);

             

             

            }

            else

            {

                                    var top_Bound = Text_FRAME.geometricBounds[0];

                                    var left_Bound = Text_FRAME.geometricBounds[1];

                                    var bottom_Bound = Text_FRAME.geometricBounds[2];

                                    var right_Bound = Text_FRAME.geometricBounds[3];

            //                      var frame_id = Text_FRAME.id;

            //                      alert ("My Geometric bounds are "

            +Text_FRAME.geometricBounds);

             

             

             

            //alert ("My Top Bound is " +top_Bound);

            //alert ("My left Bound is " +left_Bound);

            //alert ("My Bottom Bound is " +bottom_Bound);

            alert ("My right Bound is " +right_Bound);

            alert ("My Frame id is " +frame_id);

             

            if(bottom_Bound_float==bottom_Bound && right_Bound_float==right_Bound)

            {

            alert("My Bottom Bound Float is "+bottom_Bound_float);

             

            alert("My Bottom Bound sec is "+bottom_Bound);

             

            //Insert some marker

             

            //else some thing else

             

            }

             

             

             

            }

             

             

            }

             

             

            }

             

             

            }