1 Reply Latest reply on Oct 20, 2011 1:09 PM by Pet Re

    Other ways for getting a reference to the current page [ID5, JS]

    Pet Re

      To get a reference to the page you're working on (or that holds an object you want to manipulate), you could use app.activeWindow.activePage.id or app.layoutWindows[0].activePage.id.

      But when you're working on a spread and this spread fills your application window, you seldomly get the correct page reference. You could have a selection on the right page, but when you run a script with the active/layoutWindow approach, you could easily get a (wrong) reference to the left page, if that one is more 'dominant' in your program window.

       

      I work around this by using activeSpread and getting the Y-coordinate of a frame or insertionPoint on the page I'm working on. When you set the ruler origin to spread, you can determine the left or right page by looking at the Y-coordinate. If it's higher than the page width (or spine position) you're on the right hand page. You could than use if...then to assign 0 or 1 a to a variable. Finally, you can get the ID of that page: app.activeSpread.pages.item(variable).id.

       

      Perhaps this approach is helpfull for others who struggle with page references.

       

      My question is: are there other reliable (perhaps more simple) ways to get a reference to the page?

        • 1. Re: Other ways for getting a reference to the current page [ID5, JS]
          Pet Re Level 1

          Right. I should have posted the question sooner, because shortly after I found the answer I've been looking for quite long. And once again it's so simple. Nevertheless it might be usefull to share.

          For most page items like textframes and rectangles you can simpy use the property parentPage. For instance, if you have selected a rectangle you get a reference to the page with code like:

          page = doc.selection[0].parentPage.id.

          This might be usefull if you dragged a rectangle holding an image to another page and want to run a script that re-attaches the caption frame.