7 Replies Latest reply on Aug 5, 2008 12:53 PM by (Phil_Courterelle)

    Geometric bounds - odd problem

      Hi, sorry about the long set up...it's easy to show, harder to explain...using InDesign CS3 on Mac OSX 10.4...

      I've created a script that will save the position and scaling information of an image as a text file. If that image is used again, a second script searches for the corresponding text file and loads the positioning into InDesign. The data includes the difference between the position of the container and the position of the image within the container as measured via geometric bounds. The height and width of the container will always be the same but the placement within a document and on a page will vary.

      Here's the odd problem:
      Everything works fine except when an image is placed beyond the half way point of the document. Then, the horizontal positioning becomes reversed and the farther right on the page, the farther out of position the image is relative to the container. There is no change to the vertical position of the image within the container at all. It's fine.

      This holds true regardless of how the documents origins are set, so long as the data is saved after the change (it would not be surprising that data saved with different origins would not have the same effect).

      I assume the problem is how I've calculated the position of the image but I can't see it. There is no problem with the vertical position.

      Assume in the code example below that hor and vert scale is 100%

      Any and all help would be appreciated.

      pc

      --code example write data
      tell application "Adobe InDesign CS3"

      set myGraphics to all graphics of document 1

      set myChild to geometric bounds of item 1 of myGraphics
      set myParent to geometric bounds of parent of item 1 of myGraphics

      set Y1 to item 1 of myChild - item 1 of myParent
      set X1 to ietm 2 of myChild - item 2 of myParent
      set Y2 to item 3 of myChild - item 3 of myParent
      set X2 to item 3 of myChild - item 4 of myParent

      set myData to {Y1,X1,Y2,X2}

      -- more code goes here to save the data as text file ect

      end tell

      ---------------------------------------------

      -- read in data

      tell application "Adobe InDesign CS3"

      set myGraphics to all graphics of document 1

      set myParent to geometric bounds of parent of item 1 of myGraphics

      set myChild to my ReadDataFromTextFile()

      set Y1 to item 1 of myChild + item 1 of myParent
      set X1 to ietm 2 of myChild + item 2 of myParent
      set Y2 to item 3 of myChild + item 3 of myParent
      set X2 to item 4 of myChild + item 4 of myParent

      set geometric bounds of item 1 of myGraphics to {Y1, X1,Y2,X2}

      end tell
        • 1. Re: Geometric bounds - odd problem
          sstanleyau Level 4
          That sounds like a problem with ruler origin being set to spread rather than<br />page. Set it page origin (in view preferences) both when recording and<br />retrieving the values.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
          • 2. Re: Geometric bounds - odd problem
            Level 1
            The ruler origin setting makes no difference. I thought of that first off. The problem occurs regardless of whether the preference is set to spread or page.
            • 3. Re: Geometric bounds - odd problem
              Level 1
              more oddness....

              take an image that is 1 inch x 1 inch. Set the container and image origins to 0,0 at 100%.

              load the script below.

              Now move the container around on a 8 x 10 document.
              As you move beyond the position X=1 inch, the image position becomes negative relative to the container even though what is being input is same as the original. However, when the container is moved vertically to Y=5, the image is positioned ok using the script.

              This makes no sense...yet..

              ----SAVE DATA SCRIPT------

              -- main ***
              set myImageData to {}
              set myPath to ChooseFolder("set destination folder") as string

              tell application "Adobe InDesign CS3"

              --set InDesign prefs to inches decimal
              tell view preferences of document 1
              set horizontal measurement units to inches decimal
              set vertical measurement units to inches decimal
              set ruler origin to page origin
              end tell

              --set transform reference point
              --set transform reference point of document 1 to "top left"

              set myGraphics to all graphics of document 1

              set x to count (myGraphics)
              set i to 1
              repeat while i ≤ (count myGraphics)

              --control for jpegs and tiffs, exluding all other file types
              set myTest to link type of properties of item link of item i of myGraphics as string
              if myTest = "JPEG" or myTest = "jpg" or myTest = "tif" or myTest = "tiff" then

              display dialog id of item i of myGraphics as string

              set myImageList to {} -- empty list
              set myImageID to id of item i of myGraphics
              set end of myImageList to name of properties of item link of item i of myGraphics as string -- 1
              set end of myImageList to link type of properties of item link of item i of myGraphics as string --2
              set end of myImageList to absolute horizontal scale of item i of myGraphics as string --3
              set end of myImageList to absolute vertical scale of item i of myGraphics as string --4
              set end of myImageList to absolute rotation angle of item i of myGraphics as string --5
              set end of myImageList to absolute shear angle of item i of myGraphics as string --6

              -- get and calculate geometric boundaries of image -- position of image within contain minus position of container within document
              set myParent to geometric bounds of parent of item i of myGraphics
              set myChild to geometric bounds of item i of myGraphics

              set Y1 to (item 1 of myChild) - (item 1 of myParent) --7
              set X1 to (item 2 of myChild) - (item 2 of myParent) --8
              set Y2 to (item 3 of myChild) - (item 3 of myParent) --9
              set X2 to (item 4 of myChild) - (item 4 of myParent) --10

              set end of myImageList to Y1 as string --7
              set end of myImageList to X1 as string --8
              set end of myImageList to Y2 as string --9
              set end of myImageList to X2 as string --10

              --set data to main list
              set end of myImageData to myImageList
              end if

              set i to i + 1

              end repeat
              end tell

              Write_to_File(myPath, myImageData)

              -- General subroutines
              -- *****************

              on ChooseFolder(type)
              set path_to_folder to choose folder with prompt type
              return path_to_folder
              end ChooseFolder

              -- *****************

              -- *****************
              on Write_to_File(path_name, data_list)

              set x to count data_list
              set i to 1

              repeat until i > x

              --set filetype to item 2 of item i of data_list as string
              --if filetype = "jpeg" or filetype = "JPEG" then

              set file_name to item 1 of item i of data_list
              set f to (path_name as string) & file_name & ".txt"

              -- open filename for write access
              try
              set TargetFile to open for access file f with write permission
              write item i of data_list to TargetFile
              close access TargetFile
              on error
              close access TargetFile
              return
              end try

              --end if
              set i to i + 1

              end repeat

              end Write_to_File

              ---END SAVE DATA SCRIPT-------

              --START LOAD DATA SCRIPT------

              -- start main script

              -- set Search directory
              set myPath to ChooseFolder("Set Search Folder") as string

              tell application "Adobe InDesign CS3"

              --set InDesign prefs to inches decimal
              tell view preferences of document 1
              set horizontal measurement units to inches decimal
              set vertical measurement units to inches decimal
              set ruler origin to page origin
              end tell


              --get list of all graphics from document
              set myGraphics to all graphics of document 1

              set x to count (myGraphics)
              set i to 1
              repeat while i ≤ (count myGraphics)

              set myImageProp to {} --create empty list
              set afile to (myPath & name of properties of item link of item i of myGraphics as string) & ".txt"

              --Check if file exists and if so, read data
              tell application "Finder"
              if exists file afile then
              set myImageProp to my ReadData(afile)
              end if
              end tell

              --begin setting image properties - order matters
              set absolute rotation angle of item i of myGraphics to item 5 of myImageProp as real
              set absolute shear angle of item i of myGraphics to item 6 of myImageProp as real

              set myParent to geometric bounds of parent of item i of myGraphics

              set Y1 to ((item 7 of myImageProp) + (item 1 of myParent))
              set X1 to ((item 8 of myImageProp) + (item 2 of myParent))
              set Y2 to (item 9 of myImageProp) + (item 3 of myParent)
              set X2 to (item 10 of myImageProp) + (item 3 of myParent)


              set geometric bounds of item i of myGraphics to {Y1, X1, Y2, X2}

              set absolute horizontal scale of item i of myGraphics to item 3 of myImageProp as real
              set absolute vertical scale of item i of myGraphics to item 4 of myImageProp as real

              set i to i + 1
              end repeat
              end tell

              -- end main

              -- -------------------------------------------------
              -- -------------------------------------------------

              -- General subroutines/handlers

              on ChooseFolder(type)
              set path_to_folder to choose folder with prompt type
              return path_to_folder
              end ChooseFolder

              -- *****************

              on ReadData(myFile)

              set myList to {}

              try
              set TargetFile to open for access file myFile
              set myList to read TargetFile as list

              on error
              display dialog "File does not exist: " & myFile as string
              close access TargetFile
              return

              close TargetFile
              end try

              return myList
              end ReadData

              -----END LOAD DATA SCRIPT ----
              • 4. Re: Geometric bounds - odd problem
                sstanleyau Level 4
                On 13/7/08 8:56 AM, "Phil Courterelle" <member@adobeforums.com> wrote:<br /><br />> set Y2 to (item 9 of myImageProp) + (item 3 of myParent)<br />> set X2 to (item 10 of myImageProp) + (item 3 of myParent)<br /><br />That should be item *4* in that last line. But really I think you record all<br />the offsets relative to the top left corner, so in your record:<br /><br />            set Y1 to (item 1 of myChild) - (item 1 of myParent) --7<br />            set X1 to (item 2 of myChild) - (item 2 of myParent) --8<br />            set Y2 to (item 3 of myChild) - (item 1 of myParent) --9<br />            set X2 to (item 4 of myChild) - (item 2 of myParent) --10<br /><br />and in your other:<br /><br />        set Y1 to ((item 7 of myImageProp) + (item 1 of myParent))<br />        set X1 to ((item 8 of myImageProp) + (item 2 of myParent))<br />        set Y2 to (item 9 of myImageProp) + (item 1 of myParent)<br />        set X2 to (item 10 of myImageProp) + (item 2 of myParent)<br /><br />That way the pic will match position even if the frame is resized.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
                • 5. Re: Geometric bounds - odd problem
                  Level 1
                  Hi..just wanted to say thanks for the input...most appreciated...life intervened and am just getting back to it now...Thanks for the tip on setting the posiiton based on relative size of box rather than absolute size...much better idea

                  Additional question...
                  Do you have any suggestions how to further optimize the script to improve speed/performance?

                  When measured, the first 50 images are processed at 15/second, by the 200th record, it has slowed to 5 per second, by the 550th record, it has slowed to 2 records per second.

                  550 records take 2.3 minutes to process on an new Intel iMac running OSX 10.4.11 (2.4GHz processor).

                  This is a subsample of images. Most publications will have 2-3x that number of images. Perhaps I'm being unrealistic, but ... :)

                  cheers

                  pc
                  • 6. Re: Geometric bounds - odd problem
                    Level 1
                    InDesign record all your activity for Undo - in UI or by script - unfortunatelly, it can't be turned off ...
                    so when you do many operations - this undo buffer expands and slow down InDesign
                    you need to add "Save As" command (which will clear Undo buffer) with new name after processing dozen images - for example 50 or 100 - to often also isn't good - InDesign will loose to much time for read/write operations

                    or you can split your large document to smaller parts and join as book

                    robin

                    --
                    www.adobescripts.com
                    • 7. Re: Geometric bounds - odd problem
                      Level 1
                      Thanks for the input...

                      p