2 Replies Latest reply on Jan 11, 2017 4:31 AM by foltman

    spread selecting curious behavior

    foltman Level 1

      Hi!

       

      When I'm selecting whole spread and launching those two lines of code:

       

       

      var currPage = app.activeWindow.activePage;
      var myPage = app.activeDocument.pages.add(LocationOptions.after, currPage);
      

       

      curious thing happens. During the first attempt a new page is being added after first page of the spread. But after undoing it and launching script again new page is being added after second page of active spread, without any other activity from users side. Why?

       

      jf

        • 1. Re: spread selecting curious behavior
          Marc Autret Level 4

          Hi Jarek,

           

          The concept of “active page” (ie. LayoutWindow.activePage) is highly changeable as this is a GUI-dependent property. It is supposed to reflect the at-time “front-most page” that the user can see in the window area. Many DOM commands that handle pages directly impact this property because they force the window area to refresh (pages are rearranged on screen, InDesign also updates the zoom factor accordingly, and so on.)

           

          In your example, when myPage is added after currPage (which was still the active page when the command started), the newly created page becomes active and other GUI things also change or shift in a way one cannot easily control through scripting. But those “artifacts” won't be reversed when you'll hit Cmd Z. So there are serious risks that your original target (currPage) will not regain its active state even after undo. Typically the last right-sided page of the spread has become the active one as it is now the “front-most page.” And then, when you re-run the script currPage refers to this page instead of the original one.

           

          Maybe you could countervail this side effect adding app.activeWindow.activePage = currPage; at this end of your code. This should force InDesign to keep your original target in its active state while impeding parasitic shifts in the layout area.

           

          @+

          Marc

          1 person found this helpful
          • 2. Re: spread selecting curious behavior
            foltman Level 1

            Ok, I understand, this explains couple of different things as well.

            Now I have a foothold and will try do something with it.

             

            Thanks a lot!