2 Replies Latest reply on Dec 8, 2018 11:58 AM by S Hopkins

    ClearTableStyleOverrides not working?

    The Gothamite Level 1

      Aloha everyone


      I have encoutnered something amazingly strange. Basically, I have a table style called codetable. In it Column #1 has all lines aligned to the right. Column #2 has all lines aligned to the left. It's something I have to apply manually to every Code Table I have in the document, because I need to apply line numbers that aren't alway 1 - n, but can be 22-24 and then 29-35.


      A typical line that I'd convert into the codetable would be


      01     function foo() {


      So I wanted to automate this. I have done this like so:


      1. Create Paragraph style called codetable that has a tab at 10mm. I do this so that the first column of the table is always 10mm wide.
      2. Apply said character style
      3. Convert Text to table, with table style codetable
      4. Clear overrides.
      5. Be happy.


      I thought I'd automate it and since I have an amazing script by Kai Rübsamen who helped me and my colleague out a few months ago.


      So, I think to myself, let's go grab that script, strip it of all unnecessary stuff and alter it. The result:


      var curSel = app.selection[0]; 
          app.findGrepPreferences.findWhat = "^\\d{2}\\t.+$"; //Find two digits, followed by tab, followed by something until the end of the line
          app.changeGrepPreferences.appliedParagraphStyle = "codetable"; //Apply Title Paragraph Style
          app.changeGrep() //do the Grep
          app.findGrepPreferences = null; //reset all the stuff.
      var curTable = curSel.convertToTable("\t"); //Convert to table, tab marks new cell.
          curTable.appliedTableStyle = "codetable"; //apply style 
          curTable.clearTableStyleOverrides( true ); //clear table style overrides.
          app.findGrepPreferences = null; //reset all the stuff.


      This works like a charm, with one little problem. Line 09 doesn't work. At all. There's no error, there's no reaction in InDesign itself. No nothing. "No problem", I think to myself, "let's just override all cell styles". But that doesn't work either. I get an error going "curTable.clearCellOverrides( true) is not a function."


      Clearly I'm doing something wrong. I have no idea what it is or why it's wrong.


      Help, please?

        • 1. Re: ClearTableStyleOverrides not working?
          Andreas Jansson Level 2

          I realize this is 4 years ago so you are likely not interested in an answer any longer, but trying to help other people ending up here, I might as well answer...

          I had a similar problem, with cell styles that were overridden "by default". Importing a CALS xml table with no style information, into a table with a certain Table style set, the cell styles of that Table style were removed after reapplying the same TableStyle from code, after importing the xml table.


          Using clearCellStyleOverrides seems to take care of the problem. You wrote clearCellOverrides (missing the "style" part).




          ... ought to work for you too!

          • 2. Re: ClearTableStyleOverrides not working?
            S Hopkins Adobe Community Professional


            I like using the paragraph style of the text insertion point to control the default settings for a table as you have. However, I would not use it to control the width of the first column of a table. I would suggest that since this is a repetitive task, that you create a table style and apply do it all with one go. You might want to check out the series of my blogs on the subject of tables that are at yourscriptdoctor.com/blogs (2018).

            Shirley Hopkins