3 Replies Latest reply on Feb 18, 2014 5:11 AM by rob day

    Script to export object size (W, H) and coordinates(X, Y) for all objects to a file

    Andrew Reese

      Hi there all. Like the title says, I'm looking for some kind of script I can use for my InDesign CC files that will get each objects (in this case black rectangles on a page) coordinates (X, Y. using the top left as the reference point) and size (W, H in pixels) in each page and export them to a file.

       

      What it is doing is I have InDesign files that have all the different type of layouts people can choose for photo albums on the company's website. Some of those being 1 image per layout, and it goes up to 16 images in one layout, each image is represented by a black rectangle object, on a white page which represents a layout.

       

      I need something that will grab each one of the images coordinates (top-left reference point in InDesign) and size (in pixels preferrably) across all pages/layouts and export them to a text file of some sort. And a big thing is that we need it seperated by layout, so we can use another script we have made to add them to the sql layouts database on our site.

       

      And even if it has to be two seperate scripts for InDesign, one that gets size, and one that gets the coords, that is better than nothing. There are at least over 400 different images across 100 or so different layouts, seperated in different InDesign files by how many images are in each layout, so manually doing this would be time consuming, and just a pain.

       

      I searched the site and found a few older topics that covered using AppleScripts or a .jsx script in InDesign to get the coordinates or size along with some other file info, but none exactly like this or that worked. Because any I tried wouldn't work at all for exporting anything, when they made the file, they were always blank, but looking at the times they were made, it was more than likely made for CS2-CS4 so maybe they were too old to use with my InDesign CC?

       

      Anyway, anything anyone can make or help me make is apprecaited (I'm at begginer level with vanilla JavaScript so I'm limited in what I can do)

       


      So, in short we need a something that will grab each object's X Y W H per page, seperate them by the page they are in (so we know what layout/page it belongs to, since some have more than one image per layout) and export them to some sort of text file.

       

       

       


      Thanks in advance for any advice anyone can give, or if someone could make some sort of script to do this, we would be enterally grateful.

        • 1. Re: Script to export object size (W, H) and coordinates(X, Y) for all objects to a file
          rob day Adobe Community Professional & MVP

          This AppleScript displays a list of object x,y,w,h in pixel measurements. Shows how to get x, y, w, h from the geometric bounds property of a page item:

           

          Screen Shot 2014-02-14 at 6.21.20 PM.png

           

          --empty list

          copy "" to myList

           

          tell application "Adobe InDesign CS6"

              activate

              set myDoc to active document

             

              --set rulers to pixels

              set zero point of myDoc to {0, 0}

              set horizontal measurement units of view preferences of myDoc to pixels

              set vertical measurement units of view preferences of myDoc to pixels

             

              --ID Document name

              set myDocname to name of myDoc

             

              --start the list

              copy myDocname & ":" & return & return to myList

             

              tell myDoc

                  repeat with myPage from 1 to count every page

                      tell page myPage

                         

                          --all of the doc page items as a list

                          set myPageList to all page items

                          repeat with pitem from 1 to (count items of myPageList)

                             

                              --select every item on the epage

                              select item pitem of myPageList

                              try

                                  --a=Y, b=X, width=d-c, height= c-a

                                  set {a, b, c, d} to geometric bounds of item pitem of myPageList

                                 

                                  --remove as integer if you want the dimensions as numbers—not rounded

                                  set y to a as integer

                                  set x to b as integer

                                  set w to d - b as integer

                                  set h to c - a as integer

                                  -- page number

                                  set pageNumber to name

                                  --the page item's info added to the list

                                  set myItem to "P:" & pageNumber & "  " & "X:" & x & "  " & "Y:" & y & "  " & "W:" & w & "  " & "H:" & h & return

                                  copy myList & myItem & return to myList

                                 

                              end try

                          end repeat

                      end tell

                  end repeat

              end tell

             

              --display the list

              if myList is not "" then

                  display dialog myList

              end if

          end tell

          • 2. Re: Script to export object size (W, H) and coordinates(X, Y) for all objects to a file
            Andrew Reese Level 1

            Wow! That is exactly what I needed! I tweaked it to round the decimal place and save to a file instead pop up dialog, but that was stuff I didnt ask for it to do and some simple google searches helped me add it in Applescript!

             

            I'm happy to compensate you for this if you want, I can't give that much, but you've saved me a ton of time over manually doing this already!

            • 3. Re: Script to export object size (W, H) and coordinates(X, Y) for all objects to a file
              rob day Adobe Community Professional & MVP

              Nice of you to offer, but I had evrything but the width and height in an existing script, so you're welcome to use the code.