10 Replies Latest reply on Jul 29, 2014 1:07 PM by Les ONeill

    Select All (but only on page not pasteboard)

    Les ONeill Level 2

      Hi, I was wondering whether someone here might be able to write me a script that selects ONLY the objects that are on (or touching) the active page or spread?

       

      TIA

      Les

        • 1. Re: Select All (but only on page not pasteboard)
          Chinnadk Level 4

          Hi Les,

           

          For active page use the following line.

           

          app.select(app.activeWindow.activePage.allPageItems);
          

           

          For active spread use the following lines.

           

          var _spread = app.activeWindow.activeSpread.allPageItems,
              _objects = [];
          for(var i =0;i<_spread.length;i++)
          {
                  if(_spread[i].parentPage !=null)
                  {
                          _objects.push(_spread[i]);
                      }
              }
          app.select(_objects);
          

           

          Regards,

          Chinna

          • 2. Re: Select All (but only on page not pasteboard)
            Les ONeill Level 2

            Thank you so very much Chinna, very grateful

             

            Les

            • 3. Re: Re: Select All (but only on page not pasteboard)
              Laubender Adobe Community Professional & MVP

              @Chinna – interesting…
              Let's discuss your code:

               

              Snippet #1:

               

              //Select ALL OBJECTS on the active page:
              app.select(app.activeWindow.activePage.allPageItems);
              

               

              opposed to the following one I did:

               

              Snippet #2:

               

              //Select ALL first level objects on the active page:
              app.select(app.activeWindow.activePage.pageItems.everyItem().getElements());
              

               

              What can go wrong with both script snippets?

               

              The user might not expect that page items on locked layers are selected.
              Or that page items on invisible layers are selected.

               

              What can go wrong with snippet #1 additionally?

               

              Nested objects are selected as well. This might be good or not. Depends on the user's expectation.

              Usually that would be contrary to something you can do with graphical user interface of InDesign.

              You can try doing it with the Layers Panel, but you will not succeed. You cannot do it with a menu command; that's for sure.

               

              Example 1 of nested objects (a circle pasted inside a rectangle) before running snippet #1:

               

              1-RectangleWithNestedCircle-NOT-SELECTED.png

               

              Selection after running snippet #1:

               

              2-ALLPAGEITEMS-SELECTED.png

               

              Now, what does this mean?
              If the user would apply a fill color to the selection, ALL page items would get the fill. Also the nested circle.

              In contradiction to that, what would happen after using the menu command Select All where only first level page items can be selected.

              (In this example the rectangle)

               

              Let's go on with nested objects and the allPageItems array.

               

              Example 2, some rectangles on the page plus a text frame with an anchored text frame:

               

              3-SomeRectanglesPlusTextFrameWithAnchoredTextFrame-NOTHING-SELECTED.png

               

              After running snippet #1 only the anchored text frame is selected. And that is really opposed to the user's expectation.

               

              4-SomeRectanglesPlusTextFrameWithAnchoredTextFrame-ALLPAGEITEMS-SELECTED.png

               

              So, without testing any further, I would not recommend using the allPageItems array with app.select().

              I'd go for my snippet #2 that might also not meet all the user's expectations (e.g.: objects on invisible layers are selected).

               

              Or maybe better, I would write a script that implies invoking the menu command Select All and weeding out the unwanted page items on the pasteboard and on all not active pages of the active spread.

               

              Uwe

              • 4. Re: Re: Re: Select All (but only on page not pasteboard)
                Laubender Adobe Community Professional & MVP

                Additionally: it seems, that working with the selection (snippet #1 or snippet #2, also my proposed method with the menu command "Select All") would make it hard to impossible to undo the selection and revert back to the last state before running the snippet code…

                 

                Here my code handling the menu command "Select All":

                 

                //SelectAll-OnACTIVE-PAGE.jsx
                //Uwe Laubender
                
                /**
                * @@@BUILDINFO@@@ SelectAll-OnACTIVE-PAGE.jsx !Version! Tue Jul 29 2014 08:30:02 GMT+0200
                */
                
                
                selectAllOnActivePage();
                
                function selectAllOnActivePage(){
                   
                    //The active window might be no layout window!
                    try{
                    var myPageDocOffset = app.activeWindow.activePage.documentOffset;
                    }catch(e){return};
                   
                    //Tabula rasa:
                    //An anchored object could be selected. That would prevent "Select All" from the menu.
                    //Some text could be selected. "Select All" would select the whole story.
                    //And would break the script at the for loop.
                   
                    app.select(null);
                   
                    var myPageItemsToSelect = new Array();
                   
                    //Select ALL:
                    try{app.scriptMenuActions.itemByID(276).invoke()}catch(e){return};
                   
                    for(var n=0;n<app.selection.length;n++){
                       
                        if(
                        app.selection[n].parentPage != null
                        && app.selection[n].parentPage.documentOffset === myPageDocOffset
                        ){
                           
                            myPageItemsToSelect.push(app.selection[n]);
                           
                            };
                        };
                   
                    app.select(myPageItemsToSelect,SelectionOptions.REPLACE_WITH);
                
                };
                

                 

                To make it work with ALL first level objects on all pages of the active spread, simply comment out line #34 (or remove it).

                 

                Uwe

                • 5. Re: Re: Re: Select All (but only on page not pasteboard)
                  Les ONeill Level 2

                  Thanks very much for chiming in Uwe, yes, after a little testing I was getting unexpected results re: objects on invisible locked layers being selected! But that was all down to me not being specific enough in my request.

                   

                  As you rightly surmised, what I was actually trying to achieve was a 'Select All' minus pasteboard objects. So my ideal script would:

                   

                  Select All on active page or spread but only on unlocked and visible layers and it only needs to be first level objects i.e. group level, not burrowing down. But leave objects on the pasteboard alone.

                   

                  Does that last script of yours achieve that? I'm not able to test your scripts til tomorrow

                   

                  Thanks again

                  Les

                  • 6. Re: Select All (but only on page not pasteboard)
                    Laubender Adobe Community Professional & MVP

                    Les wrote:

                    Does that last script of yours achieve that? I'm not able to test your scripts til tomorrow

                     

                    Yes. But test it well. You can make two diverse ones out of it:
                    One for the active page (line #34 not commented out) and one for all pages on the active spread (line #34 commented out).

                     

                    Uwe

                    • 7. Re: Select All (but only on page not pasteboard)
                      Laubender Adobe Community Professional & MVP

                      What is not available with this script is an undo, that will bring you back to your original selection.
                      That would require an additional script. And maybe a user interface, that will combine all two scripts together.

                       

                      Uwe

                      • 8. Re: Select All (but only on page not pasteboard)
                        Laubender Adobe Community Professional & MVP

                        @Chinna – Nevertheless, using allPageItems in conjunction with app.select() is highly interesting!
                        (If we consider some side effects)

                         

                        Thank you, Chinna, to point that out…

                        Uwe

                        • 9. Re: Select All (but only on page not pasteboard)
                          Chinnadk Level 4

                          Hi Uwe,

                           

                          Thanks for your clarification.

                           

                          I don't have much experience in indesign scripting that is the reason i haven't concentrate about the side effects.

                           

                          Regards,

                          Chinna

                          • 10. Re: Re: Re: Select All (but only on page not pasteboard)
                            Les ONeill Level 2

                            Just a final note to say thank you Uwe, your script from post 4 is exactly as desired, so thanks again

                             

                            Les