5 Replies Latest reply on Dec 13, 2010 11:34 PM by Haakenlid

    Help with Indesign script

    M.Jay.Victor Level 2

      Would anyone be willing to help me with a script? I need to Find the first table using "ERTStyle1" table style, convert it to text, change the text style to "Tabfix" paragraph style, then convert it back into a table using the table style "ERTStyle2" convert the top row to a header. It needs to repeat this process until there are no tables left using the "ERTStyle1" table style.

       

      I think I could almost do this myself using VBScript, but I am relatively new to scripting, and to be honest, I am hoping I can use this script to jump start my knowledge of VB in Indesign.

        • 1. Re: Help with Indesign script
          M.Jay.Victor Level 2

          I do not think I have ever asked for help on these forums, and not gotten a single responce, so is there somewhere I could have asked the question better? Is VBscript just not used, or is there maybe somewhere someone could point me to start figuring out the script I am after?

          • 2. Re: Help with Indesign script
            Peter Kahrel Adobe Community Professional & MVP

            There aren't many VB scripters hanging around here anymore, that's why you don't get much response. You say that you're relatively new to scripting, so maube you could think of using JavaScript instead. You bound to get much more response on your JS queries.

             

            As to your table script, why would you want to convert to text, apply styles, and convert back to tables? Why not simply use the Tabfix paragraph style in all cells of the ERTStyle2 table style and apply that to each table.

             

            Peter

            • 3. Re: Help with Indesign script
              M.Jay.Victor Level 2

              Unless I am missing something, that would not manage the column sizes of my tables. I really am just looking for a way to manage cell, row, and column sizes on a large number of tables, which can not be done with styles:(

              • 4. Re: Help with Indesign script
                [Jongware] Most Valuable Participant

                So all of this is just to set the column widths to the sizes pre-defined in a paragraph style, i.e., always the same?

                I feel like I almost could do that in VB!

                But in Javascript, all it needs is sth in the ilk of

                 

                var myWidths = [ 10, 50, 100, 50, 12 ]; // in whatever units you fancy
                var myTable = app.activeDocument.stories[0].tables[0];  // (just grabbing some table)
                for (i=0; i<myTable.columns.length; i++)
                 myTable.columns[i].width = myWidths[i % myWidths.length];
                

                 

                .. and the most interesting thing here (written from top of my head) is the "myWidths" lookup: it doesn't matter how many columns there are in this table, 'cause the widths array wraps around. (But you won't need this because you know all of your widths in advance.)

                • 5. Re: Help with Indesign script
                  Haakenlid Level 3

                  I added a loop to JongWare's script that will look through all tables in the active document and only applies the changes to the tables with the correct table style.

                   

                  var myTableStyle = "ERTStyle1";
                  var myWidths = [ 10, 5, 10, 5, 12 ]; // in whatever units you fancy
                  var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); 
                  for (var n=0; n < myTables.length; n++){
                       if (myTables[n].appliedTableStyle.name==myTableStyle){
                            for (var i=0; i<myTables[n].columns.length; i++){
                                 myTables[n].columns[i].width = myWidths[i % myWidths.length];
                            }
                       }
                  }