• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

spread selecting curious behavior

Explorer ,
Jan 10, 2017 Jan 10, 2017

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

733

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 10, 2017 Jan 10, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 11, 2017 Jan 11, 2017

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 06, 2018 Aug 06, 2018

Copy link to clipboard

Copied

LATEST

I was wanting to loop through my spreads selecting each one as I go an I ended up using this.

for(j=0;j<numPages/2;j++){

        app.activeWindow.activeSpread=app.activeDocument.spreads;///This activates the next spread

          pItems = app.windows[0].activeSpread.pageItems;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines