5 Replies Latest reply on May 12, 2016 6:42 AM by Russ Ward

    filter  to body pages

    markrazzz

      I need to filter only bodypage within this iterator below

      anyone know an easy way to do this?

      thanks

       

       

      var doc= app.ActiveDoc;

      iterate(doc)

       

      function iterate(doc)

      {

              var pgf = doc.FirstPgfInDoc;

             while (pgf.ObjectValid())

          {

       

      /*

           if(bodypage)   

           {

           //do something

           }

      */

              pgf = pgf.NextPgfInDoc;//NextPgfInFlow

      }

       

       

      }

        • 1. Re: filter  to body pages
          Wiedenmaier Level 3

          Hi,

           

          one possible way is this.

           

          If you want to check all flows, you have to iterate them all and check if they are on a body page.

          For this you have to get the TextFrame and the unanchored frame from that.

          This unanchored frame delivers the page and you can check if it's a body page.

          if you've found the body page, you can get next pages.

           

          var flow = app.ActiveDoc.FirstFlowInDoc;

          while (flow.ObjectValid())

          {

               var textFrame = flow.FirstTextFrameInFlow;

               var unanchoredFrame = textFrame.FrameParent;

               var page = unanchoredFrame.PageFramePage ;

               if (page.Type != Constants.BodyPage)

               {

                    flow = flow.NextFlowInDoc;

                    continue ;

               }

               while(page.ObjectValid())

               {

                    //Iterate all BodyPages and do you actions here

                    page = page.PageNext ;

               }

               flow = flow.NextFlowInDoc;

          }

           

          if you only want to check main flow, you can leave first loop, get MainFlowInDoc from active doc.

           

           

          If start position is a paragraph you can get textFrame, from that paragraph:

           

          var textFrame = pgf.InTextFrame;

           

          from here its the same than above.

           

           

          In both way it's possible getting same body page more than once. So you have to check if it's allready processed.

           

          Code isn't testet, so I hope all works for you.

          Markus

           

           

           

           

          • 2. Re: filter  to body pages
            markrazzz Level 1

            thank you so much, I will give this a shot

             

            thank you!

            • 3. Re: filter  to body pages
              frameexpert Level 4

              Here is a general purpose function that will get the page object of any other FrameMaker object:

               

              function getPage (obj) {
              
                  var frame = 0, cell = 0;
                  var objType = "";
              
                  while (obj) {
              
                      frame = obj;
                      objType = obj.constructor.name;
              
                      switch (objType) {
                          case "SubCol" :
                              obj = obj.ParentTextFrame;
                              break;
                          case "Tbl" :
                              obj = obj.TopRowSelection.FirstCellInRow;
                              break;
                          case "Cell" :
                          case "Pgf" :
                          case "AFrame" :
                              obj = obj.InTextFrame;
                              break;
                          case "TextLine" :
                          case "TextFrame" :
                          case "UnanchoredFrame" :
                          case "Arc" :
                          case "Ellipse" :
                          case "Group" :
                          case "Inset" :
                          case "Line" :
                          case "Math" :
                          case "Polygon" :
                          case "Polyline" :
                          case "Rectangle" :
                          case "RoundRect" :
                              if (obj.FrameParent.ObjectValid()) {
                                  obj = obj.FrameParent;
                              } else {
                                  obj = 0;
                              }
                              break;
                          default:
                              // Prevent endless loop if unknown object type is found.
                              obj = 0;
                              break;
                      }
                  }
                  if (frame) {
                      return frame.PageFramePage;
                  } else {
                      return 0;
                  }
              }
              

               

              So, where you have this:

               

              /*

                   if(bodypage)  

                   {

                   //do something

                   }

              */

               

              you can use this:

               

              if ((getPage(pgf)) && (getPage(pgf).constructor.name === "BodyPage")) {
                   // do something here.
              }
              

               

              Please let me know if you have any questions or comments.

               

              Rick

              • 4. Re: filter  to body pages
                Ch. Efstathios

                Hi, I have the following function which seems to be like yours but I can't make it work for tables!

                 

                IntT GetPageType (F_ObjHandleT docId, F_ObjHandleT objectId)
                {
                  F_ObjHandleT oldParentId;
                
                  F_ObjHandleT parentId = objectId;
                
                  IntT parentType = FO_TextFrame;
                
                  while (parentType != FO_BodyPage &&
                    parentType != FO_MasterPage &&
                    parentType != FO_RefPage &&
                    parentType != FO_HiddenPage)
                  {
                    oldParentId = parentId;
                
                    parentId = F_ApiGetId(docId, parentId, FP_FrameParent);
                
                    if (!parentId)
                    {
                      parentId = F_ApiGetId(docId, oldParentId, FP_PageFramePage);
                
                      if (!parentId)
                      {
                        break;
                      }
                    }
                
                    parentType = F_ApiGetObjectType(docId, parentId);
                  }
                
                  return parentType;
                }
                

                 

                Can you help me?

                • 5. Re: filter  to body pages
                  Russ Ward Level 4

                  Hi Ch, please avoid reviving these old threads for loosely-related followup questions. I realize you are just looking for help, but it makes it difficult to keep things organized for readers and contributors alike. Please refer to your current post for this issue:

                   

                  How to filter tables from body pages only?

                   

                  Russ