Skip to main content
Participating Frequently
August 18, 2010
Question

Scripting for different numbers of table rows in cs3

  • August 18, 2010
  • 1 reply
  • 422 views

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

This topic has been closed for replies.

1 reply

Jongware
Community Expert
Community Expert
August 18, 2010

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

Participating Frequently
August 18, 2010

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.

Jongware
Community Expert
Community Expert
August 18, 2010

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.cells.length; c++)
  {
   if (table.rows.cells.contents)
   {
    for (; c<table.rows.cells.length; c++)
     table.rows.cells.topEdgeStrokeWeight = 1;
    break;
   }
  }
}
} else
alert ("You were supposed to be somewhere inside a Table");