3 Replies Latest reply on Mar 25, 2010 9:35 PM by Steven..

    Scripting newbie needs help with table script

    JAC159

      Not new to InDesign, but new to scripting. Using InDesign CS4 on Mac.

       

      The set up: InDesign document is open. Table style is defined (Table SP). Paragraph style is defined (SP). Text is selected (tabs between columns, return between rows).

       

      Would like script that converts selected text to table using table style "Table SP" then applies paragraph style "SP" to the paragraph the table is in.

       

      Have tried to adapt scripts from the Scripting Guide, but am getting no where. Would appreciate your help with this. Thank you.

        • 1. Re: Scripting newbie needs help with table script
          Steven.. Level 3

          just to get you started

           

          var tbl = app.activeDocument.selection[0].convertToTable("     ","\n");
          tbl.appliedTableStyle = app.activeDocument.tableStyles.itemByName("Table SP");
          tbl.storyOffset.paragraphs[0].appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName("SP");
          

           

          Didn't check it, and I hope it works

          1 person found this helpful
          • 2. Re: Scripting newbie needs help with table script
            JAC159 Level 1

            Thanks Steven. With a couple of edits that did the trick. It just needed the "\t" and a "\r" instead of the "\n".

             

            You just saved me some 2500 clicks!

            • 3. Re: Scripting newbie needs help with table script
              Steven.. Level 3

              Save those clicks to help the next person in need.

               

              Yes \r is the correct syntax. What I find interesting is that in the OMV it says

              Note: Can be defined as any single character, such as a letter, number, or punctuation mark, or by typing a space or tab. Use the actual character rather than its name, such as ',' rather than 'Comma'. Precede double or single quotes or a backslash with an extra backslash as an escape character. For paragraphs, use ^p.

               

              However ^p throws an error, while \r works.