19 Replies Latest reply on Feb 2, 2012 5:15 PM by TrapperBob

    Table and cell Style

    M Karthik Level 1

      Dear all,

       

      Greetings....

       

      The below script is working perfectly in indesign CS3 to apply the table and cell style. But in indesign CS4 is showing runtime error. Kindly help me on this........

       

      var myTable = app.activeDocument.stories.everyItem().tables; 
      
      for (var n=0; n < myTable.length; n++)
      { 
           myTable[n].appliedTableStyle = "Table Style 1"; 
           myTable[n].cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]");
           myTable[n].cells.everyItem().clearCellStyleOverrides (true); 
      
           alert(myTable[n].rows.length);
      
          for (var a = 1; a < myTable[n].rows.length - 2; ++a)
           {
                 myTable[n].rows[a].cells.everyItem().appliedCellStyle = "T body";
                 alert(a);
           }
        
          myTable[n].rows[0].cells.everyItem().appliedCellStyle = "T col hd";//First Row 
           myTable[n].rows[-1].cells.everyItem().appliedCellStyle = "T body bot";//Last Row
      
      }
      

       

      Thanks

      Karthik

        • 1. Re: Table and cell Style
          csm_phil Level 4

          Hi M Karthik,

           

          Your code  JS code is working perfecet on InDesign CS4 platform Mac OS 10.5.6. Can you please post the runtime error snapshot. And also can you do this please clear/delete the InDesign Preferences after that try again once.

           

          thx

          csm_phil

          • 2. Re: Table and cell Style
            M Karthik Level 1

            Hi

            I am working on Windox XP CS4. As instructed, i have placed the runtime error screenshot image for yours reference....

            script_error.JPG

             

            Thanks

            Karthik

            • 3. Re: Table and cell Style
              Colin Flashman Adobe Community Professional

              can't help you with the script you have, but have seen an alternative script which may help. written by martin fischer. go to:

               

              http://indesign.hilfdirselbst.ch/tabellen/allen-tabellen-eines-dokuments-ein-tabellenforma t-zuweisen.html

              • 4. Re: Table and cell Style
                csm_phil Level 4

                Hi Karthik,

                 

                Please try the below JS Code and revert.

                 

                 

                var myTable = app.activeDocument.stories.everyItem().tables; 
                 for (var n=0; n < myTable.length; n++){ 
                //~      myTable[n].appliedTableStyle = "Table Style 1"; 
                //~      myTable[n].cells.everyItem().appliedCellStyle = app.activeDocument.cellStyles.item("[None]");
                //~      myTable[n].cells.everyItem().clearCellStyleOverrides (true); 
                
                // Please check the table cell styles name is correct or not?
                    var myActiveTable = myTable[n];
                    myActiveTable.rows.itemByRange(0,-2).cells.everyItem().appliedCellStyle = "TB";
                    myActiveTable.rows[0].cells.everyItem().appliedCellStyle = "TCH";//First Row 
                   myActiveTable.rows.itemByRange(-2,-1).cells.everyItem().appliedCellStyle = "TBB";//Last Row
                    }
                

                 

                Picture 1.png

                 

                the above js code output is like this snapshot.

                 

                thx

                csm_phil

                • 5. Re: Table and cell Style
                  M Karthik Level 1

                  Thanks csm_phil. you have done a great job for me. Thanks a lot..................

                  • 6. Re: Table and cell Style
                    TrapperBob Level 1

                    Is this for CS4 only? I try in CS5 (win7) and get nothing but errors.

                    i just want to apply a style over rides and a simple table styles to all my tables, but i can't find anything that works.  PLEASE HELP.

                    • 7. Re: Table and cell Style
                      John Hawkinson Level 5

                      If you don't tell us what the errors are, we cannot help you.

                      • 8. Re: Table and cell Style
                        John Hawkinson Level 5

                        You must attach screenshots using the web interface, you cannot do so via email.

                        You should probably go to the web site and edit your posts, they are inscrutable, and also contain extraneous quoted information from the previous posts.

                         

                        There's not enough information about your problem to help you.

                        It sounds like it is detailed enough to merit a thread of its own.

                        • 9. Re: Table and cell Style
                          TrapperBob Level 1

                          Hi John,

                          I'm at a loss as to how come the script works on one system but not mine(CS5 win7).

                          What are the coloured letters near the end of each of the last 3 lines of code?

                          What are the variables that I need to load with my table style name?

                          thanks

                          FYi, i've begun the brutal task of manual formatting, the deadline is looming.

                           

                          Table_and_cell_Style-error.gif

                          • 10. Re: Table and cell Style
                            John Hawkinson Level 5

                            Robert:

                              Your error message refers to a string on line 2, "RB_Base_Table.length", which does not appear on line 2 of any of the versions of the script in this thread. Instead they have "myTable." Did you alter the script?

                             

                            If so, why did you do so? As written, it operates on all tables in the document.

                             

                            The colored letters are syntax highlighting intended to make it easier to read and understand the script. You can ignore the colors and simply cut and paste thes script verbatim.

                            • 11. Re: Table and cell Style
                              TrapperBob Level 1

                              This came up when i ran the unaltered scipt on a 1 page doc (CS5 win7) containing a 3 col by 7 row table.

                              Table_and_cell_Style-error-Unchanged script.gif

                              • 12. Re: Table and cell Style
                                John Hawkinson Level 5

                                I'm not sure what you're expecting. Line 9 of the script sets the style of some rows to a style named "TB."

                                 

                                I'm sorry for saying that the script needed to run unaltered. Clearly that's not the case. You do need to change the styles that the script uses (in double-quoted strings) into styles that are applicable to your situation. Even then the script is a bit specific...

                                • 13. Re: Table and cell Style
                                  TrapperBob Level 1

                                  FANTASTIC, thank you John, the cell style now applies.

                                  what xyntax should i use for appling a table style?

                                  thanks

                                  • 14. Re: Table and cell Style
                                    John Hawkinson Level 5

                                    what syntax should i use for appling a table style?

                                    myActiveTable.appliedTableStyle="Whatever";

                                    • 15. Re: Table and cell Style
                                      TrapperBob Level 1

                                      Thanks John,

                                      I found a sample that sort of works;

                                      myTable[n].appliedTableStyle = "RB_Base_Table";

                                      What does the [n] mean?

                                       

                                      My latest issue is that cell and table styles over-rides need to also be applied in this script.

                                      Though I'm half through my current 'table fest' project, it still behooves me to run a good script to finish the second half of my book in a fraction of the time that the first half took. Hopefully a good script will also alow me to have the weekend off after week of 10 and 12 hour daze.

                                      • 16. Re: Table and cell Style
                                        John Hawkinson Level 5

                                        myTable[n].appliedTableStyle = "RB_Base_Table";

                                        What does the [n] mean?

                                        It refers to the nth table, where n is a variable. Because it is a for loop, its contents execute once for every table.

                                        In this case, "myTable[n]" is the same as "myActiveTable," because of the assignment that makes that so.

                                         

                                        My latest issue is that cell and table styles over-rides need to also be applied in this script.

                                        It is not clear what you are asking for, if anything.

                                        • 17. Re: Table and cell Style
                                          TrapperBob Level 1

                                          Thanks John,

                                          sorry about the ambigiuity of my request.

                                          What I need is the syntax to clear overrides for paragraphs, cell and table styles, Please.

                                          thanks

                                          • 18. Re: Table and cell Style
                                            John Hawkinson Level 5

                                            Have you looked through the documentation, or the object model at http://jongware.mit.edu, or searched on the scripting forum for "clear overrides"?

                                            It's really expected that you put a bit of effort into figuring this out yourself.

                                             

                                            For a table, you can use myActiveTable.clearTableStyleOverrides();.

                                            For cells, similarly, instead of (or in addition) to setting .appliedCellStyle, you can also call .clearCellOverrides().

                                            For paragraph styles, it's a bit more complicated since you don't deal with paragraph attributes anywhere.

                                            I suppose you can likely use cells.everyItem().paragraphs.everyItem().clearOverrides().

                                            • 19. Re: Table and cell Style
                                              TrapperBob Level 1

                                              Thank-you John,

                                              And yes, initially, i did put a lot effort into it.

                                              However, debugging the scripts that i did find was eating away at my production time, which was totally stressing out my manager.

                                              I’m sorry for the bother that i’ve caused you, but your efforts have been tremendously appreciated!

                                              Once again, thank-you John.

                                              Robert Bourassa

                                              Senior Production Artist