2 Replies Latest reply on Jun 17, 2009 8:01 AM by Orielwen

    Applescript to apply table and cell styles in IDCS4

    Orielwen Level 1

      I have an Applescript to format all tables in a document the way I want them.  It's adapted from a previous version that didn't use styles, which works perfectly.  This script creates the styles if they're not present, and this bit works fine, but when it starts trying to apply them to tables it falls over.

      tell application "Adobe InDesign CS4"
           tell active document
                set BlackColor to color "Black"
                set SolidStroke to stroke style "Solid"
           end tell
           tell active document
                try
                     set myTablePara to paragraph style "4.2 Table text"
                on error
                     set myTablePara to make paragraph style with properties {name:"4.2 Table text", applied font:"Helvetica Neue", font style:"Regular", point size:"8.5", leading:"10"}
                end try
                try
                     set myBasicCell to cell style "Basic cell"
                on error
                     set myBasicCell to make cell style with properties ¬
                          ¬
                               {name:¬
                                    "Basic cell", bottom edge stroke weight:0 ¬
                                    , bottom edge stroke color:BlackColor ¬
                                    , bottom edge stroke type:SolidStroke ¬
                                    , right edge stroke weight:0 ¬
                                    , right edge stroke color:BlackColor ¬
                                    , right edge stroke type:SolidStroke ¬
                                    , top edge stroke weight:0 ¬
                                    , top edge stroke color:BlackColor ¬
                                    , top edge stroke type:SolidStroke ¬
                                    , left edge stroke weight:0 ¬
                                    , left edge stroke color:BlackColor ¬
                                    , left edge stroke type:SolidStroke ¬
                                    , left inset:¬
                                    "0p4", right inset:¬
                                    "0p4", top inset:¬
                                    "0p4", bottom inset:¬
                                    "0p4", vertical justification:top align ¬
                                    , applied paragraph style:myTablePara}
                end try
                try
                     set myHeader to cell style "Header"
                on error
                     set myHeader to make cell style with properties ¬
                          {name:¬
                               "Header", based on:myBasicCell ¬
                               , bottom edge stroke weight:¬
                               "0.5pt", top edge stroke weight:"0.75pt", vertical justification:bottom align ¬
                               }
                end try
                try
                     set myFooter to cell style "Final Row Cell"
                on error
                     set myFooter to make cell style with properties ¬
                          {name:¬
                               "Final Row Cell", based on:myBasicCell ¬
                               , bottom edge stroke weight:¬
                               "0.75pt"} ¬
                               
                end try
                try
                     set myLeftCol to cell style "First Column Cell"
                on error
                     set myLeftCol to make cell style with properties ¬
                          {name:"First Column Cell", based on:myBasicCell, left inset:0}
                end try
                try
                     set myLeftHeader to cell style "First Row, First Column Cell"
                on error
                     set myLeftHeader to make cell style with properties ¬
                          {name:"First Row, First Column Cell", based on:myHeader, left inset:0}
                end try
                try
                     set myLeftFooter to cell style "First Column Last Row Cell"
                on error
                     set myLeftFooter to make cell style with properties ¬
                          {name:"First Column Last Row Cell", based on:myFooter, left inset:0}
                end try
                
                try
                     set myTableStyle to table style "Horizon"
                on error
                     set myTableStyle to make table style with properties {name:¬
                          "Horizon", body region cell style:¬
                          myBasicCell, header region cell style:¬
                          myHeader, footer region cell style:¬
                          myFooter, left column region cell style:myLeftCol}
                end try
           end tell
           set allTables to every table of every story of active document
           repeat with i from 1 to count of allTables
                set myTable to item i of allTables
                set table style of myTable to myTableStyle
                set properties of cells of myTable to ¬
                     {cell style:myBasicCell}
                set properties of cells of first column of myTable to ¬
                     {cell style:myLeftCol}
                set properties of cells of first row of myTable to ¬
                     {cell style:myHeader}
                set properties of cells of last row of myTable to ¬
                     {cell style:myFooter}
                set properties of first cell of first row of myTable to ¬
                     {cell style:myLeftHeader}
                set properties of first cell of last row of myTable to ¬
                     {cell style:myLeftFooter}
                clear cell style overrides
                clear table style overrides
           end repeat
      end tell
      

      When it gets to 'set table style of myTable to myTableStyle' it says 'Can’t set table style of table id 224 of text frame id 220 of page id 190 of spread id 185 [the first table] of document \"Untitled-1\" to table style id 264 [the newly generated style] of document \"Untitled-1\".'  But I can't tell why.  Can anyone help?