Skip to main content
Participant
September 14, 2012
Question

filter to body pages

  • September 14, 2012
  • 5 replies
  • 1453 views

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

}

}

This topic has been closed for replies.

5 replies

Inspiring
September 14, 2012

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

 

markrazzzAuthor
Participant
September 14, 2012

thank you so much, I will give this a shot

thank you!

frameexpert
Community Expert
Community Expert
September 16, 2012

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

www.frameexpert.com