5 Replies Latest reply on Dec 8, 2010 11:15 AM by Kasyan Servetsky

    Get bounds of image and bounds of frame of image?

    joesickspack Level 1

      How can I get both the geometric bounds of an image AND the geometric bounds of the frame of the image as I loop through all the images in a document?

        • 1. Re: Get bounds of image and bounds of frame of image?
          Kasyan Servetsky Level 5

          Here is a sample:

          var link, image, frame;
          var doc = app.activeDocument;
          var graphics = doc.allGraphics;
          
          for (var i = 0; i < graphics.length; i++) {
               link = graphics[i].itemLink;
               image = link.parent;
               frame = image.parent;
               $.writeln("Name: " + link.name);
               $.writeln("Image GB: " + image.geometricBounds);
               $.writeln("Frame GB: " + frame.geometricBounds);
          }
          

           

          Kasyan

          • 2. Re: Get bounds of image and bounds of frame of image?
            joesickspack Level 1

            Thank you, but . . . I forgot to mention that I am using AppleScript rather than JavaScript. Sorry.

            • 3. Re: Get bounds of image and bounds of frame of image?
              Kasyan Servetsky Level 5

              Here's the Apple Script version of the script:

              tell application "Adobe InDesign CS3"
                   set TheDocument to active document
                   set TheGraphics to all graphics in TheDocument
                   repeat with n from 1 to (count TheGraphics)
                        set TheGraphic to item n of TheGraphics
                        set TheLink to item link of TheGraphic
                        set TheImage to parent of TheLink
                        set TheFrame to parent of TheImage
                        set ImageGB to geometric bounds of TheImage
                        set FrameGB to geometric bounds of TheFrame
                        set ImageVB to visible bounds of TheImage
                        set FrameVB to visible bounds of TheFrame
                        set TheText to "Name: " & name of TheLink & return & ¬
                             "Geometric Bounds of Image = " & ImageGB & return & ¬
                             "Geometric Bounds of Frame = " & FrameGB & return & ¬
                             "Visible Bounds of Image = " & ImageVB & return & ¬
                             "Visible Bounds of Frame = " & FrameVB & return & return
                        my write_to_file(TheText, true)
                   end repeat
              end tell
              
              on write_to_file(this_data, append_data)
                   try
                        set the log_file to (path to desktop as text) & "Geometric and Visible Bounds Report" as text
                        set the open_target_file to open for access file log_file with write permission
                        if append_data is false then set eof of the open_target_file to 0
                        write this_data to the open_target_file starting at eof
                        close access the open_target_file
                        return true
                   on error
                        try
                             close access file log_file
                        end try
                        return false
                   end try
              end write_to_file
              

              Kasyan

              • 4. Re: Get bounds of image and bounds of frame of image?
                joesickspack Level 1

                Thank you. That worked flawlessly.

                • 5. Re: Get bounds of image and bounds of frame of image?
                  Kasyan Servetsky Level 5

                  You are welcome. I was able to write it only tonight since I have a Mac only at work and my working week starts on Wednesday.

                   

                  Kasyan