6 Replies Latest reply on Nov 1, 2016 6:22 AM by Oriup

    script a 3 column vs 4 column table

    Schnazalope

      I have been trying hard to figure out scripting in a short short time to speed up a job. Client typically provides copy in tab format which goes fast but this time a lot of it is in tables. I figured out a few rudimentary scripts to help me out but I was wondering if anyone would be willing to help me out with a table script. The examples I find aren't commented too much so I can't figure out what is going on.

       

      Basically the tables are fairly similar. I have either a 3 column or a 4 column table. All headers would be the same style no matter the table, with the type vertically aligned at the bottom with the cell. If it is a 3 column table I need widths of (well I figured this ou):

      app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = "48pt";

      app.activeDocument.stories.everyItem().tables.everyItem().columns[1].width = "162pt";

      app.activeDocument.stories.everyItem().tables.everyItem().columns[2].width = "32.75pt";

      app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().minimumHeight = "3pt";

       

      If 4 columns then I need:

      app.activeDocument.stories.everyItem().tables.everyItem().columns[0].width = "48pt";

      app.activeDocument.stories.everyItem().tables.everyItem().columns[1].width = "128.15pt";

      app.activeDocument.stories.everyItem().tables.everyItem().columns[2].width = "32.75pt";

      app.activeDocument.stories.everyItem().tables.everyItem().columns[3].width = "32.75pt";

      app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().minimumHeight = "3pt";

       

      The rest of the rows in either a 3 or 4 column table would all have the same paragraph style.

      Would be good to apply cell and table styles as well which are the same for all tables.

       

      I know I am asking a lot but for this recurring huge job it would save me days.

       

      Or can someone point me to a good resource of examples that are explained?

        • 1. Re: script a 3 column vs 4 column table
          Peter Kahrel Adobe Community Professional & MVP

          When you apply table styles, the cell and therefore the paragraph styles fall into place automatically (most of them, anyway). Here's something to begin with (untested):

           

          tables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
          for (i = 0; i < tables.length; i++) {
            tables[i].appliedTableStyle = app.activeDocument.tablestyles.item('xyz');
            tables[i].columns[0].width = "48pt";
            tables[i].columns[1].width = "162pt";
            tables[i].columns[2].width = "32.75pt";
            tables[i].rows.everyItem().minimumHeight = "3pt";
          }
          

           

          Peter

          • 2. Re: script a 3 column vs 4 column table
            tpk1982 Level 4

            Hi,

             

            I hope we need to first identify the table contains 3 column or 4 by script. After that only we proceed further. Because the variation of 2nd column value.

            • 3. Re: script a 3 column vs 4 column table
              Peter Kahrel Adobe Community Professional & MVP

              Well, you could do something like this:

               

              for (i = 0; i < tables.length; i++) {
                tables[i].appliedTableStyle = app.activeDocument.tablestyles.item('xyz');
                tables[i].rows.everyItem().minimumHeight = "3pt";
                if (tables[i].columns.length === 3) {
                  // three columns
                } else {
                  // four columns
                }
              }
              

               

              P.

              1 person found this helpful
              • 4. Re: script a 3 column vs 4 column table
                Schnazalope Level 1

                I have this setup now but get the error on line 7: Object does not support the property 'tablestyles'.  I know enough to be dangerous with programming but stumble around with it. I'm not sure what each command does or how to invoke them. How would one apply paragraph styles to a particular cell or column? Example. I want the the body rows (anything from row 2 down to be a style called 'Course lists'. Then columns 3 and 4 (depending on if it is 3 or 4 columns but column 3 is the same content type for both) to be styled with a paragraph style called 'Course lists right' (for right alignment of the credits) and then followed by the top row to be a paragraph style called 'Credits head'.

                 

                And again I hate asking for this much help. Is there a service to pay someone to code it for me? After I get a working code I can look it over and figure out how to adjust as needed.

                 

                 

                tables = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); 

                    for (i = 0; i < tables.length; i++) { 

                         if (tables[i].columns.length === 3) { 

                        // three columns 

                            tables = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); 

                    for (i = 0; i < tables.length; i++) { 

                      tables[i].appliedTableStyle = app.activeDocument.tablestyles.item('Course table'); 

                      tables[i].columns[0].width = "48pt"; 

                      tables[i].columns[1].width = "162pt"; 

                      tables[i].columns[2].width = "32.75pt"; 

                      tables[i].rows.everyItem().minimumHeight = "3pt"; 

                    } 

                      } else if (tables[i].columns.length === 4){ 

                        // four columns 

                            tables = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); 

                    for (i = 0; i < tables.length; i++) { 

                      tables[i].appliedTableStyle = app.activeDocument.tablestyles.item('Course table'); 

                      tables[i].columns[0].width = "48pt"; 

                      tables[i].columns[1].width = "128.15pt"; 

                      tables[i].columns[2].width = "32.75pt";

                      tables[i].columns[3].width = "32.75pt"; 

                      tables[i].rows.everyItem().minimumHeight = "3pt"; 

                    } 

                      } 

                    } 

                • 5. Re: script a 3 column vs 4 column table
                  Schnazalope Level 1

                  I don't want to waste anyone's time (but I would like to learn this). I have found a plugin that does what I need it to do and I will use that. thank you for the time investment put in.

                  I am using Smart Style plugin in case anyone asks.

                  • 6. Re: script a 3 column vs 4 column table
                    Oriup Level 1

                    Hi Sir,

                     

                    Just correct:

                    tablestyle to tableStyle;

                     

                    Everything is well.

                     

                    You are Great.

                     

                    Sumit