Skip to main content
Known Participant
February 8, 2016
Question

FM Script to find the pagenumber of a paragraph

  • February 8, 2016
  • 1 reply
  • 881 views

I am working on a frame maker script and flowing from first Pgf to the last Pgf in search of selected PgfFmt. When I found the required PgfFmt I need to list the page number in which page the Pgf is present. Using Scripting I can able to find the PgfFmt but I cant able to find the actual page in which it exist.

Thanks & Regards,

Lohithkumar

This topic has been closed for replies.

1 reply

frameexpert
Community Expert
Community Expert
February 8, 2016

Here is a function that I use to find the page of a particular object. This was adapted from an old FDK example. FrameScript has a shortcut Page property on most objects, but in ExtendScript and the FDK you have to use something like this:

function getPage (obj) {

   

    // Gets the page object that contains the object passed in.

   

    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.FirstRowInTbl.FirstCellInRow;

                break;

            case "Row" :

                obj = obj.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;

    }

}

www.frameexpert.com
Known Participant
February 9, 2016

Hi, the code is working fine

Thank You

frameexpert
Community Expert
Community Expert
February 9, 2016

Please mark the answer as Correct. Thank you.

www.frameexpert.com