• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

getting body page from text location

Engaged ,
Jun 25, 2019 Jun 25, 2019

Copy link to clipboard

Copied

Hi there,

I'm Fighting with getting the page (BodyPage) of a certain text location.

Let's say you have a paragraph, starting on page 1 and ending on page 2.

How can I get the FO_BodyPage of second page, where paragraph ends

Thanks for any ideas

Markus

TOPICS
Scripting

Views

623

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 25, 2019 Jun 25, 2019

This might be better. Of course, you should adapt the code into a callable function.

var doc, pgf, textLoc, prop, page, textFrame;

doc = app.ActiveDoc;

pgf = doc.TextSelection.beg.obj;

// Make a text location at the end of the paragraph.

textLoc = new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1);

// Get the text frame of the text location.

prop = doc.GetTextPropVal (textLoc, Constants.FP_InTextFrame);

textFrame = prop.propVal.obj;

// Navigate up to the page object.

alert (textFrame.FrameParent.PageFrame

...

Votes

Translate

Translate
Community Expert ,
Jun 25, 2019 Jun 25, 2019

Copy link to clipboard

Copied

Hi Markus,

How about something like this:

#target framemaker

var doc, pgf, textList, page;

doc = app.ActiveDoc;

pgf = doc.TextSelection.beg.obj;

textList = pgf.GetText (Constants.FTI_PageBegin);

if (textList.length) {

    page = textList[textList.length - 1].obj;

    alert (page);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2019 Jun 25, 2019

Copy link to clipboard

Copied

This might be better. Of course, you should adapt the code into a callable function.

var doc, pgf, textLoc, prop, page, textFrame;

doc = app.ActiveDoc;

pgf = doc.TextSelection.beg.obj;

// Make a text location at the end of the paragraph.

textLoc = new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1);

// Get the text frame of the text location.

prop = doc.GetTextPropVal (textLoc, Constants.FP_InTextFrame);

textFrame = prop.propVal.obj;

// Navigate up to the page object.

alert (textFrame.FrameParent.PageFramePage);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jun 25, 2019 Jun 25, 2019

Copy link to clipboard

Copied

Rick's method has worked well for me. I add one additional thing... to ensure that I have the page frame, I navigate up FP_FrameParent until it returns nothing, then I know the last valid FrameParent was the top-level page frame. This makes it more resilient for embedded frames, etc. In other words, depending upon the setup of the doc, the immediate FrameParent may not be the frame page and therefore PageFramePage will not get you the page.

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 25, 2019 Jun 25, 2019

Copy link to clipboard

Copied

LATEST

Put Rick's and Russ' answers together...

var doc = app.ActiveDoc; 
var pgf = doc.TextSelection.beg.obj; 

var pageStart = getPage(pgf, true);
var pageEnd = getPage(pgf, false);
alert(pageStart.PageNum + " =>" + pageEnd.PageNum );

function getPage(pgf, checkBegin)
{
    // Make a text location at the end of the paragraph. 
    var textLoc = null;
    if (checkBegin)
        textLoc = new TextLoc (pgf, 0); 
    else
        textLoc = new TextLoc (pgf, Constants.FV_OBJ_END_OFFSET - 1); 
    // Get the text frame of the text location. 
    var prop = doc.GetTextPropVal (textLoc, Constants.FP_InTextFrame); 
    var textFrame = prop.propVal.obj; 
    var pageFrame = textFrame.FrameParent;
    while(pageFrame.FrameParent.ObjectValid())
    {
        pageFrame.FrameParent;
    }
    return pageFrame.PageFramePage;
}

Thanks guys for your quick help. Solutions are Always so easy, if you know the way to it 😉

My excuse is the hot weather here in Germany 😉

Thanks Russ for your hint to the loop. As I can only mark one answer as the Right one, I decided for Rick, sorry Russ and thanks Rick

Have a great day

Markus

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines