2 Replies Latest reply on Jul 20, 2010 6:55 AM by Rand0mUser

    Script for placing an image in its own paragraph (for eBooks, etc)

    Rand0mUser Level 1

      This is for flowing text formats.

       

      With the cursor placed at the beginning of the paragraph, the script needs to:

      - paste an image from the clipboard at that insertion point

      - place a break paragraph return (to put the image in its own paragraph)

      - apply a paragraph style to the image (zero leading)

      - add an XML tag "image"

       

      Is this doable?

        • 1. Re: Script for placing an image in its own paragraph (for eBooks, etc)
          [Jongware] Most Valuable Participant

          Absolutely.

           

          - After you did a previous manual "copy", from within InDesign or in just about any other program, app.paste() will do a regular paste operation on your current cursor position.

          - use app.selection[0].insertionPoints[-1].contents = "\r" to 'insert' a paragraph return before your current cursor position.

          - use app.selection[0].paragraphs.previousItem(app.selection[0].paragraphs[0]) to set properties of the paragraph before the one your cursor is in (as you may already know, scripting usually does not move the cursor around).

          - so, since 'allGraphics' is the property that holds images for paragraphs, app.selection[0].paragraphs.previousItem(app.selection[0].paragraphs[0]).allGraphics[0] targets 'the first graphic in the previous paragraph that you are currently in', and you can set its properties in turn to anything you'd like.

           

          As for the finishing touch, setting the XML tag of an image, I don't know how to do that ... there doesn't seem to be a 'tag' method for graphics.

          1 person found this helpful