4 Replies Latest reply on Aug 18, 2010 5:19 AM by GordonEddey

    Scripting for different numbers of table rows in cs3

    GordonEddey

      As always thank you for the help.

       

      My question: is there a simple newbie way to script for stroke placements when the numbers of rows in the category between the stroke will vary. I have not even attempted to script this style, as frankly I don't know where to start, but here is an explanation of what I need:

       

      The table foodstuff contains:

      animal, vegetable, fruit

       

      Under animal there is:

      beef, lamb, pork, poultry

       

      Under vegetable there is:

      potato, pepper, onion

       

      Under fruit there is:

      orange

       

      If wanted a line under each category, ie after poultry, after onion, and after orange how would I go about it.

       

      Thank you to all who have helped me so far, either by reading answers to other people's queries, or by responding directly to my own

        • 1. Re: Scripting for different numbers of table rows in cs3
          [Jongware] Most Valuable Participant

          Can you post a mock-up picture of what the result ought to be?

          • 2. Re: Scripting for different numbers of table rows in cs3
            GordonEddey Level 1

            jongwareTest.jpg

            Hi Jongware, thank you for your quick response. As you can see from the picture there are levels of complexity and tables within tables in the result I ultimately need to achieve. The first question pertains to drawing a table wide line for each major category, eventhough these contain a different number of rows. Please ignore the color breaks as these are an attempt to indicate the different elements in each part of the table.

             

            Thanks for your help.

            • 3. Re: Scripting for different numbers of table rows in cs3
              [Jongware] Most Valuable Participant

              Interesting ... I don't think there is a newbie-level answer to this challenge. It comes down to finding the first (left-to-right) cell that contains text, and adding a line on top of it all the way to the last cell in that row.

               

              Here's a first attempt:

               

              table = app.selection[0];
              if (table.hasOwnProperty("baseline"))
               table = table.parent;
              if (table instanceof Cell)
               table = table.parent;
              if (table instanceof Column)
               table = table.parent;
              if (table instanceof Row)
               table = table.parent;
              if (table instanceof Table)
              {
               table.cells.everyItem().properties = {topEdgeStrokeWeight:0, bottomEdgeStrokeWeight:0, leftEdgeStrokeWeight:0, rightEdgeStrokeWeight:0};
               table.rows.lastItem().bottomEdgeStrokeWeight = 1;
               for (r=0; r<table.rows.length; r++)
               {
                for (c=0; c<table.rows[r].cells.length; c++)
                {
                 if (table.rows[r].cells[c].contents)
                 {
                  for (; c<table.rows[r].cells.length; c++)
                   table.rows[r].cells[c].topEdgeStrokeWeight = 1;
                  break;
                 }
                }
               }
              } else
               alert ("You were supposed to be somewhere inside a Table");
              
              • 4. Re: Scripting for different numbers of table rows in cs3
                GordonEddey Level 1

                Thanks Jongware. I'm sure this answers the question, although at this point it is well beyond my brain. Really appreciate the help.