2 Replies Latest reply on Mar 3, 2017 11:27 AM by IronPaw

    Can i get selected spread?

    IronPaw

      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]

        • 1. Re: Can i get selected spread?
          Laubender Adobe Community Professional & MVP

          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

          1 person found this helpful
          • 2. Re: Can i get selected spread?
            IronPaw Level 1

            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[n].pageColor);
               }
            
               // Document pages read:
               for (var n = 0; n < docPagesLength; n++) {
              docPagesColors.push(docPages[n].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[n].pageColor != 1851876449) {
              resultArray.push(masterPages[n]);
               }
              $.writeln(n+"\t"+"master | pageColor"+"\t"+masterPages[n].pageColor.toString() );
               }
            
               // Document pages read:
               for (var n = 0; n < docPagesLength; n++) {
               if(docPages[n].pageColor != 1851876449) {
              resultArray.push(docPages[n]);
               }
              $.writeln(n+"\t"+"doc | pageColor"+"\t"+docPages[n].pageColor.toString() );
               }
            
               return returnPagesColors();
               }
            
               function returnPagesColors() {
            
               // Master pages return:
               for (var n = 0; n < masterPagesLength; n++) {
              masterPages[n].pageColor = masterPagesColors[n];
               }
            
               // Document pages return:
               for (var n = 0; n < docPagesLength; n++) {
              docPages[n].pageColor = docPagesColors[n];
               }
            
               // Selected pages return:
               return resultArray;
            
               }
            
            }
            
            main();