4 Replies Latest reply on May 17, 2011 9:54 AM by allisonblake

    [AS][CS5] Duplicate selection to new document

    allisonblake Level 1

      Hi everyone,

      I'm working on a script that will allow me to make a PDF or printout of a selection in InDesign by duplicating the selection to a new document.

      I'm having difficulty with the portion of the script that duplicates the selection to a new document.

      I'm trying to follow the instructions in the CS5 scripting guide but it's not working.

       

      Here's my code:

      --make a new document from selection
      tell application "Adobe InDesign CS5"
          set mySelection to selection
          if (count of mySelection) = 0 then
              display dialog "Nothing selected." & return & "Select something and then run the script." buttons {"OK"} cancel button {"OK"}
          end if
          tell document 1
             
              --make group in order to get width/height of selection
              if (count of mySelection) > 1 then
                  set myItem to make group with properties {group items:(mySelection)}
              else
                  set myItem to item 1 of selection
              end if
              set theBounds to geometric bounds of myItem
              set theHeight to (item 3 of theBounds) - (item 1 of theBounds)
              set theWidth to (item 4 of theBounds) - (item 2 of theBounds)
             
              --undo the grouping so selection is unchanged
              undo
          end tell
         
          --make new document sized to the width/height of the selection
          set myDoc to make new document with properties {document preferences:{page width:theWidth, page height:theHeight}}
         
          --duplicate selection to new document
          tell mySelection
              set myDupe to duplicate to page 1 of myDoc
          end tell
      end tell

       

      I get the following error:

      {«class crec» id 201 of «class sprd» id 186 of document id 2 of application \"Adobe InDesign CS5\", «class crec» id 202 of «class sprd» id 186 of document id 2 of application \"Adobe InDesign CS5\", «class crec» id 207 of «class sprd» id 186 of document id 2 of application \"Adobe InDesign CS5\"} doesn’t understand the duplicate message." number -1708 from {«class crec» id 201 of «class sprd» id 186 of document id 2, «class crec» id 202 of «class sprd» id 186 of document id 2, «class crec» id 207 of «class sprd» id 186 of document id 2}

       

      Thanks!

        • 1. Re: [AS][CS5] Duplicate selection to new document
          Muppet Mark-QAl63s Level 4

          Alison, you just have a minor omission… You have not declared your object to dupe… This worked with a little tweek…

           

           

          --make a new document from selection

          tell application "Adobe InDesign CS5"

          set mySelection to selection

          if (count of mySelection) = 0 then

          display dialog "Nothing selected." & return & ¬

          "Select something and then run the script." buttons {"OK"} cancel button {"OK"}

          end if

          set openDoc to document 1

          tell openDoc

          --make group in order to get width/height of selection

          if (count of mySelection) > 1 then

          set myItem to make group with properties ¬

          {group itemsmySelection)}

          else

          set myItem to item 1 of selection

          end if

          set theBounds to geometric bounds of myItem

          set theHeight to (item 3 of theBounds) - (item 1 of theBounds)

          set theWidth to (item 4 of theBounds) - (item 2 of theBounds)

          end tell

           

          --make new document sized to the width/height of the selection

          set myDoc to make new document with properties ¬

          {document preferences:{page width:theWidth, page height:theHeight}}

           

          --duplicate selection to new document

          tell openDoc

          set myDupe to duplicate myItem to page 1 of myDoc

          --undo the grouping so selection is unchanged

          undo

          end tell

          --re-posistion in new size doc

          tell myDoc

          move myDupe to {0, 0}

          end tell

          end tell

           

          Sorry I've forgotten where you turn off the Emoticons… dammed : + (

          • 2. Re: [AS][CS5] Duplicate selection to new document
            allisonblake Level 1

            Thank you!

            This works great...Although now I realize I need to figure out how to deal with items that have strokes...the width/height is not being calculated correctly.

            Thanks again for you help!

            • 3. Re: [AS][CS5] Duplicate selection to new document
              John Hawkinson-NXenhA Level 1

              Use visible bounds instead of geometric bounds?

              1 person found this helpful
              • 4. Re: [AS][CS5] Duplicate selection to new document
                allisonblake Level 1

                Bingo!

                Thanks, John.

                I hadn't actually expected a response to that, I was just thinking out loud.

                I'm glad I did!