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
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
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);
}
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);
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
Copy link to clipboard
Copied
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