This content has been marked as final. Show 4 replies
One of the most elusive properties in InDesign/JS is "page number" -- which is ironic in a page-layout program. It is in fact the name of a page:
Pages also have a documentOffset property that might be more useful than the page name (depending on your intentions). It's a number while the name is a string. But the documentOffset ignores any formatting you might have done to the page name, and also is independent of any numbering changes you might have made with your sections.
This will not work if the frame is in a group (which most of the time is not the case, so it probably doesn't matter). But just in case, the following method will reliably find the correct page, but is not necessarily the most efficient, depending on the number of pages in the document.
>var myFrame = myStory.textContainers;
var myPage = GetPageOfFrame(myFrame);
var myPageName = myPage.name; // the page's folio, a string
var myPageOffset = myPage.documentOffset; // the nth page of the document, a number
]for (var p = 0; p < app.documents.pages.count(); pi++)
]]var myPageItems = app.documents.pages[p].allPageItems;
for (var pi = 0; pi < myPageItems.length; p++)
]]]if (myPageItems[pi] == myFrame)
There's a another method to deal with frames in a group (or group of groups), which involves a recursive handler to keep looking at the parent of the parent, etc, but the one I use is flawed in certain circumstances so I use this one when reliability is important.
Thanks to you all. At least that bit is now working! I'll salt your
pearls of wisdom away for future use.