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

Can i get selected spread?

New Here ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

I need to get indexes of spread that selected in pages tab.

So how can i do it.

I try use app.selection but it work only if I select spread by script...

for example:

app.select(app.activeDocument.spreads.itemByRange(1,3));

$.writeln(app.selection); //[object Spread],[object Spread],[object Spread]

TOPICS
Scripting

Views

799

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
Community Expert ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

Hi IronPaw,

I recently solved this problem here:

Re: active page vs selected page

For InDesign CS6 there is a very clean method. Also shown in the same thread.

For CC and above I am using page labels to get the info.

And if your document already has page labels applied you have to extend the code to gather all relevant page lables before and apply them again after the script gathered all selected pages or spreads in the Pages panel.

Regards,

Uwe

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
New Here ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

LATEST

Thanks you, Uwe.

Your example send me to the right way.

1) get all pageColor and remember it

2) set all pageColor to NOTHING

3) set pageColor to BLACK for all selected pages/spreads in menu

4) push all items with pageColor != NOTHING to resultArray

5) set old pageColors to its pages/spreads

6) return resultArray

Nice!!!

My code example below.

function main() {

   var selectedPagesArray = getSelectedPages();
   $.writeln( selectedPagesArray );
}

function getSelectedPages(){

   var resultArray = [];
   var masterPagesColors = [];
   var docPagesColors = [];


   if (app.documents.length == 0) {

   return resultArray;
   }

   if (!app.panels.itemByName("$ID/Pages").visible) {

   return resultArray;
   }

   var doc = app.documents[0];

   var masterPages = doc.masterSpreads.everyItem().pages.everyItem().getElements();
   var masterPagesLength = masterPages.length;
   var docPages = doc.pages.everyItem().getElements();
   var docPagesLength = docPages.length;

   return getCurrentPagesColors();

   function getCurrentPagesColors() {

   // Master pages read:
   for (var n = 0; n < masterPagesLength; n++) {

  masterPagesColors.push(masterPages.pageColor);
   }

   // Document pages read:
   for (var n = 0; n < docPagesLength; n++) {

  docPagesColors.push(docPages.pageColor);
   }

   return getSelectedPages();

   }

   function getSelectedPages(){

  doc.masterSpreads.everyItem().pages.everyItem().pageColor = PageColorOptions.NOTHING;
   doc.pages.everyItem().pageColor = PageColorOptions.NOTHING;

   $.writeln('masterPagesColors: ' + masterPagesColors);
   $.writeln('docPagesColors: ' + docPagesColors);

   try {

  app.menus.item("$ID/PagesPanelPopup")

  .submenus.itemByName("$ID/PageAttributesSubMenu")

  .submenus.itemByName("$ID/PageColorLabelMenu")

  .menuItems[-1].associatedMenuAction.invoke();
   } catch(e) {

   // Master "None" selected in the Pages Panel
   return resultArray;
   }

   // Master pages read:
   for (var n = 0; n < masterPagesLength; n++) {

   if(masterPages.pageColor != 1851876449) {

  resultArray.push(masterPages);
   }

  $.writeln(n+"\t"+"master | pageColor"+"\t"+masterPages.pageColor.toString() );
   }

   // Document pages read:
   for (var n = 0; n < docPagesLength; n++) {

   if(docPages.pageColor != 1851876449) {

  resultArray.push(docPages);
   }

  $.writeln(n+"\t"+"doc | pageColor"+"\t"+docPages.pageColor.toString() );
   }

   return returnPagesColors();
   }

   function returnPagesColors() {

   // Master pages return:
   for (var n = 0; n < masterPagesLength; n++) {

  masterPages.pageColor = masterPagesColors;
   }

   // Document pages return:
   for (var n = 0; n < docPagesLength; n++) {

  docPages.pageColor = docPagesColors;
   }

   // Selected pages return:
   return resultArray;

   }

}

main();

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