This content has been marked as final. Show 8 replies
You can go about this in one of two ways:
1. Determine the page that holds the selection by looking up the parental chain until you find a page (watch out for characters in that chain; that means the selection is inside an anchored object, so you have to use the parent text frame to get to the page).
2. You can use the active page property of the front layout window. This too requires some checking; the front window holding the selection could be a story window.
Many thanks for the help.
Method 1: Parent of selection (or insertion point) is text flow; parent of that is document. So that didn't get me to the page. Any hints on how to get the active page this way?
Method 2 works just fine.
If the selection is text, you must go immediately for the parent text frame. Sorry, I should have mentioned that. But the method worked, so that's fine.
That looks very useful. Thanks. I hope you don't mind me pasting it below. By the way, how do you invoke it? I tried doing so from a 'tell document' call and got an error ('active document doesn't undrestand the getParentPage message').
tell application "Adobe InDesign CS2"
if class of thisObject = page then
return my getParentPage(parent of thisObject)
One of the key elements is to make sure to use the keyword "my" in front of the function, because you are referring to the function inside the script and not an InDesign function (which is what you are talking to by default inside the 'tell InDesign' statement).
tell application "Adobe InDesign CS3"
tell active document
set thisPage to my getParentPage(item 1 of parent text frames of selection)
display dialog "This is page " & name of thisPage
Mind you this only works as long as your selection only spans one page. I presume item 1 would always force it to give you the first page the selection was associated with.
I recall the 'my' thing now. Trouble is i script infrequently enough that my brain doesn't retain these necessary rules.
So after some experimentation it seems to me that the only way to get a page from a text selection is via 'parent text frames'. Just using 'parent' won't get you to a page ID. And 'parent text frames' must be plural not singular! Quirky.
Anyhoo, it works like a charm, Eric. Many thanks.
But bear in mind that a text selection can be overset or it can be in a text frame on the pasteboard (no page in parental chain) or on a master page/spread.