1 person found this helpful
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.
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!