12 Replies Latest reply on Jul 3, 2012 2:40 AM by gnits999

    Select all image objects in a document, layer, page

    Corwin86

      Hi,

       

      I'm reading the "Scripting Guide", but still I haven't found what I'm looking for...

       

      I need to select, with three different JS Script, all the images that are inside the current selected InDesign document, layer and page.

       

      Can someone help me, please?

       

      Many thanks!

        • 1. Re: Select all image objects in a document, layer, page
          [Jongware] Most Valuable Participant

          "Selecting some stuff" is very rarely the objective of a script. Usually, it's not the selecting that's important, but what you do with that selection.

           

          Selecting objects with Javascript has the same limitations as selecting in the user interface: for instance, you cannot select items on more than one spread. Perhaps it's easier to immediately do (or don't do -- there is no "try") your thing on the images, instead of trying to select all of them.

          • 2. Re: Select all image objects in a document, layer, page
            Corwin86 Level 1

            Hi [Jongware] ,

             

            the problem is that already have a script that "do" something with all the images selected by the user, and I want to "extend" his functionality: I want that the user can decide to execute the script an all the images inside the document, or the layer, or the page.

            • 3. Re: Select all image objects in a document, layer, page
              [Jongware] Most Valuable Participant

              Then it'd be a good idea to re-write that script. Instead of

               

              with (selection)

                stuff
              

               

              make it work with a function:

               

              do_stuff_on (selection)

               

              so you can add a dialog, for example, at the start, and then do something like

               

              for every image
                do_stuff_on (image)
              

               

               

              (Sorry if the above is a mess. I tried to apply 'plain code formatting' to my pseudocode, but this editor is such an unbelivevable piece of ****, it won't let me and messed up my post by way of thanks.)

              • 4. Re: Select all image objects in a document, layer, page
                Corwin86 Level 1

                Hi,

                 

                ok, but my problem remain . How I "translate" the "for every image"?

                • 5. Re: Select all image objects in a document, layer, page
                  [Jongware] Most Valuable Participant

                  Iterate over the graphics in the document, or on the page, or in the selection (or what-have-you).

                   

                  For the entire document, for example, can easily be done using document.allGraphics:

                   

                  for (i=0; i<app.activeDocument.allGraphics.length; i++)
                  {
                   // Advisable to do some pre-selection here
                   // For example:
                   if (app.activeDocument.allGraphics[i].imageTypeName == "TIFF")
                   {
                    do_your_stuff (app.activeDocument.allGraphics[i]);
                   }
                  }
                  function do_your_stuff (img)
                  {
                   alert (img.itemLink.name);
                  }
                  

                   

                  Page and Layer also have an allGraphics property, but if you need the graphics for a specific layer on a specific page, you need to get a little creative because "Page" works across all layers, and "Layer" works across all pages.

                  1 person found this helpful
                  • 6. Re: Select all image objects in a document, layer, page
                    Corwin86 Level 1

                    Thanks very much!

                     

                    But if I wanted to select all the images (ATTENTION: not to "obtain" all the images)?

                    I mean, set the "focus" on every single image of the document, as if I had hand-selected them.

                    • 7. Re: Select all image objects in a document, layer, page
                      [Jongware] Most Valuable Participant

                      As I said in my first answer, scripting doesn't allow you to do stuff that you cannot do in the interface. You cannot select images across all spreads. (Try it.)

                      • 8. Re: Select all image objects in a document, layer, page
                        gnits999 Level 1

                        Jongware, this piece of code is really really really really  useful.   Thanks a heap.

                         

                        What would be perfect would be to add sample code in the Do_your-stuff to :.

                         

                        1. Move the image to the centre of the page defined by page margins

                        2. Add a stroke around the image.

                         

                         

                        I am really please to find this gem of a discussion, as it answers so many questions for me trying to dip my toe into InDesign scripting for the first time and will solve a workflow issue for me of several years standing.

                         

                        Thanks again.

                         

                        Matt (Dublin, Ireland).

                        • 9. Re: Select all image objects in a document, layer, page
                          [Jongware] Most Valuable Participant

                          Here you go. Rather than going through the calculations myself (perfectly doable but boring), I let InDesign work for me. First, I set the 'parent' of the image to the page size -- remember that the image is a separate entity inside an existing frame --, then use Center Content, then Fit Frame to Content.

                           

                          If you have facing pages, you need to set your ruler temporarily to "Ruler Per Page", otherwise it won't work -- everything will end up on the left page.

                           

                          function do_your_stuff (img)
                          {
                          img.parent.geometricBounds = [0,0, app.activeDocument.documentPreferences.pageHeight, app.activeDocument.documentPreferences.pageWidth];
                          img.parent.fit (FitOptions.CENTER_CONTENT);
                          img.parent.fit (FitOptions.FRAME_TO_CONTENT);
                          img.parent.strokeColor = app.activeDocument.swatches.item("Black");
                          img.parent.strokeWeight = 2;
                          }
                          
                          • 10. Re: Select all image objects in a document, layer, page
                            gnits999 Level 1

                            I very much appreciate the very prompt and expert response.

                             

                             

                             

                            I used the margins as the reference because I can use document set up to modify these for a number of scenarios /  templates  without going into the script (and add weight to the bottom of pages, etc). I am using data merge to populate InDesign template  pages.

                             

                             

                             

                            I now have an automated workflow for producing my portfolio prints including all necessary metadata (striving for 5 years at least), with the added advantage I can create pdfs for electronic documents.  A massive productivity saving and eliminates a boring and error prone manual process.

                             

                             

                             

                             

                             

                             

                             

                            I spent a few hours trying to apply, by script, an object  style to the image boundary.  Is there an easy way to do this.

                             

                             

                             

                            Finally.

                             

                             

                             

                            What the best reference book / resource to help me with the DOM. (I am using CS 6). [I have looked at O’Reilly media..bought “Scripting InDesign CS3/4 with JavaScript” .

                             

                             

                             

                            What is the best Development Environment (which might help me get the syntax right for using Methods, Properties, etc..)

                             

                             

                             

                             

                            Update.    

                             

                            I eventually found your documentation re  CS 6. Well done and what a difference it makes.  This means -----> I eventually could use the DOM and slowly work out the Properties / Methods, etc..

                             

                            ------> Which meant I could figure out how to apply the Stroke Styles.

                             

                            ------> Which means that I am now just curious about your views on best Books / Resources re InDesign Javascript  and best development environments.

                             

                            Message was edited by: gnits999

                            • 11. Re: Select all image objects in a document, layer, page
                              [Jongware] Most Valuable Participant

                              gnits999 wrote:

                               

                              Update.    

                               

                              I eventually found your documentation re  CS 6. Well done and what a difference it makes.  This means -----> I eventually could use the DOM and slowly work out the Properties / Methods, etc..

                               

                              ------> Which meant I could figure out how to apply the Stroke Styles.

                               

                              ------> Which means that I am now just curious about your views on best Books / Resources re InDesign Javascript  and best development environments.

                               

                              I avoid the ESTK as much as possible, I hate it. </personal_view>

                               

                              So I don't use any 'development environments', I write most of my scripts using TextWrangler (Mac)/TextPad (Windows), and sprinkle lots of alerts and confirmation dialogs through my code to use for debugging. But that's just my workflow.

                               

                              I don't have any specific recommendations for books or resources. Peter Kahrel's book is one of the very few targeted specifically to InDesign -- if you can read German, Gregor Fellenz' is another very thorough guide.

                               

                              I got most of the InDesign DOM under control, the weird thing is at times I need some help with the pure Javascript parts! But for that there are lots of on-line resources. Most of these examples are meant for web browsers, but with some trial and error you can filter out the pure browser-related parts and replace it with ID's DOM objects.

                              • 12. Re: Select all image objects in a document, layer, page
                                gnits999 Level 1

                                My views on  ESTK are exactly the same as yours, probably even more acute,  as I do not have your depth of experience in relation to either Java or the Dom and also fairly new to InDesign,

                                 

                                 

                                 

                                In summary, here is the the challenge I had ….and the final solution (in case anyone else wants to follow the same trail).

                                 

                                 

                                 

                                I was totally frustrated that there is so much manual effort required to marry metadata and images (both in Lightroom) to produce professional quality portfolio layouts. I am really frustrated that Lightroom does not fill this basic objective.  All use of metadata in output modules is a kludge, including the new book module.  I was also frustrated that Photoshop / InDesign provided such poor tools to provide the user with the ability to properly place metadata on a printed page (or electronic equivalent) without massive manual effort (ie cut and paste).

                                 

                                I discovered the Caption Tool within InDesign…which gave me hope…. But this is really a very very very  klunky tool.  I can make loads of suggestions on how to improve it. Disappointed it was not improved in CS6.

                                 

                                I finally discovered Data Merge within InDesign.  I could finally create a template within InDesign, manage my titles, captions, location, dates and other metadata in  Lightroom, create my images with exact output sharpening and resolution, place them on an InDesign template page with no changes (even minor) to dpi (which ruins the output sharpening) and also place all my metadata on the page via InDesign template plus datamerge.

                                 

                                [I think there is a bug in data merge.  If I select “collapse frame to image” (so stroke is correct)  and “centre” the image it appears to collapse first and align second…stupid…always leaving the image in the top left and also…now my metadata text fields are  no longer lined up with the image (vertically or horizontally.]

                                 

                                Your help with the script has allowed me to re position the image where it should be (ie centre of the margins rather than page works for me) and re-align all of my metadata. 

                                 

                                So so sweet. A dream fulfilled. A completely automated workflow from Lightroom to the final printed/electronic page.  Also, I now have the basic tool set to tackle any other similar challenges.

                                 

                                 

                                Thank you so much.

                                 

                                1. PS. 1. I will watch this InDesign scripted space for improvements in the future, now that I have the key into this world.

                                 

                                1. Ps. 2  Most  of this would not  be necessary if Adobe allowed a user place a default metadata  field as a source for content within a text box (Lightroom. Photoshop and InDesign)  and allowed a text field to be linked to an image box (without the need to overlap the boxes). In my mind a short cut, instead of doing this properly.  So simple.