1 Reply Latest reply on May 29, 2009 8:06 AM by Mr Bounce

    [AS] Copy/Paste graphics

    Mr Bounce

      Hi,

      Just wondering if anyone can help... l'm trying to copy/paste graphics from one document to another.

       

      I've been doing this my getting the file path of item link of graphic 1 and then setting this value to the frame on the other document - then setting the offset etc to move it to the correct place - which works great. (see below code)

       

      The problem l've got it sometimes the original graphic file doesn't exists so it does not work - what l want to do is then copy the 'preview' image you see on the document and paste that in the box on the other document - just like a normal copy/paste

       

      Any ideas on a nice way of doing this?

       

      This is my current copy/paste methods l talked about:

       

       

      on copyItem(boxName)

       

           try

           tell application "Adobe InDesign CS3"

                set myCopyDocument to active document

                set proceed to false

       

                tell myCopyDocument

                     set theSelection to graphic 1 of page item boxName

                     set theTarget to parent of theSelection

       

                     set FilePathOfImage to file path of item link of graphic 1 of theTarget

                     set {a, b, c, d} to geometric bounds of theSelection

                     set {w, x, y, z} to geometric bounds of theTarget

                     set xOff to a - w

                     set yOff to b - x

                end tell

       

                return {true, FilePathOfImage, xOff, yOff}

       

           end tell

           on error msg

                display dialog "Can not copy original image: " & msg

                return {false, "", 0, 0}

           end try

       

      end copyItem

       

       

      on pasteItem(boxName, FilePathOfImage, xOff, yOff)

       

           tell application "Adobe InDesign CS3"

       

       

            try

                tell myPasteDocument

                     set myImage to place FilePathOfImage on page item boxName

                     set {a, b, c, d} to geometric bounds of myImage

                     set geometric bounds of myImage to {a + xOff, b + yOff, c + xOff, d + yOff}

                end tell   

           on error msg

       

                display dialog "Can not place original image: " & msg

       

           end try

           end tell

      end pasteItem

       

       

      Regards, Gary.

        • 1. Re: [AS] Copy/Paste graphics
          Mr Bounce Level 1

          Worked out a way of doing it with the following:

           

          property myDocuments : {}
          set boxName to "pic1"

           

          tell application "Adobe InDesign CS3"
             
              -- Source
              set MyRectangles to page item boxName of document 1
              set MyRectangle to item 1 of MyRectangles
              set thePage to parent of MyRectangle
              set thePageNumber to name of thePage
             
              -- Target
              set MyTargetRectangles to page item boxName of document 2
              set MyTargetRectangle to item 1 of MyTargetRectangles
              set theTargetPage to parent of MyTargetRectangle
              set theTargetPageNumber to name of theTargetPage
              set {y, x, l, h} to geometric bounds of MyTargetRectangle
             
              -- Duplicate onto document 2
              set MyTargetRectangleCopy to duplicate MyRectangle to page theTargetPageNumber of document 2
             
              -- Delete old target
              delete MyTargetRectangle
             
              -- Move new target to old targets place
              move MyTargetRectangleCopy to {x, y}
             
          end tell