Copy link to clipboard
Copied
I'm trying to modify the Table script on https://indesignsecrets.com/tackling-tables-through-scripting.php by Theunis De Jong to allow me to modify any number of tables in a given document to have the same look and feel.
We use footer rows and the "hide last" feature to allow long tables to continue over a page.
I need to be able to target the first footerRow of each table. I am able to target any of the body rows with:
table.rows[0].properties = {fillColor: "Paper",
bottomEdgeStrokeColor: "CBoC Blue",
bottomEdgeStrokeWeight: ".75pt",
topEdgeStrokeWeight: "0pt",
height: "32pt" };
I I thought something like the following would work for a footer row:
table.footerRows[0].cells.properties = {topEdgeStrokeColor: "CBOC Blue",
topEdgeStrokeWeight: "0pt"};
I've been using the list of table properties: http://jongware.mit.edu/idcs6js/pc_Table.html but I have not been able to figure out which property to use to target a footer row.
Some of the properties I've tried are
RowTypes.FOOTER_ROW
Where did you see the footerRows property of the Table class? I can't find it in the scripting reference! I'm afraid you can't use something that doesn't exist.
table.rows is the collection of all rows in the table.
You can loop through all of them and check each row's rowType property which can be one of the following:
If it is 'footer row' you can calculate the first one using the table.footerRowCount property which, as th
...Copy link to clipboard
Copied
Where did you see the footerRows property of the Table class? I can't find it in the scripting reference! I'm afraid you can't use something that doesn't exist.
table.rows is the collection of all rows in the table.
You can loop through all of them and check each row's rowType property which can be one of the following:
If it is 'footer row' you can calculate the first one using the table.footerRowCount property which, as the name suggests, gives you the number of footer rows in the table.
So, though the solution isn't lying on the surface, it's possible. Here are a couple of examples:
Here's the approach suggested by Trevor (unlike you, the OP was looking for the first row on each page)
And here's my code: the same approach but adjusted to me needs (I was looking for the first body row)
Hope it helps!
— Kas
Copy link to clipboard
Copied
Thanks! I guess I have misunderstood how tables work under the hood. I did not understand that a table is a collection of rows and the only difference between a header row and a body row and a footer row is the property
Thanks for pointing me in the right direction!
Copy link to clipboard
Copied
Crossposting on indesignsecrets!
Kas, I think we can step this loop for checking if a row is a footer row:
main();
function main() {
var allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for (var i = 0; i < allTables.length; i++) {
var curTable = allTables;
var numberOfFooterRows = curTable.footerRowCount;
var fRows = curTable.rows.itemByRange(-numberOfFooterRows, -1).getElements();
var firstFooterRow = fRows[0];
firstFooterRow.properties = {topEdgeStrokeColor: "CBOC Blue"};
}
}
Kai
Copy link to clipboard
Copied
Hi guys!
As to me, here I could give only a general advice. To write a specific script, I need to have a real document for testing. Ideally two versions of it: before and after running the script.
I remember, when I was writing the script I mentioned in my last post, I had to rework it a few times because the client changed the structure of the document so the script obviously stopped working.
Many factors may influence the way a script runs so without having the file it's just assuming and guessing. (My personal opinion)
— Kas
Copy link to clipboard
Copied
Hi Kas,
one structural change I can foresee in a document with tables is that tables are sometimes nested to table cells or are positioned to footnotes. In that case we could do a TEXT find action to get the character that represents a table "<0016>" and look for texts[0].tables[0] in the found character.
( And then there could be objects looking like tables, but are no tables at all, but a bunch of rectangles, graphic lines and text frames. )
Regards,
Uwe
Copy link to clipboard
Copied
My apologies for cross posting here and Indesign Secrets Scripting forum. I was unsure what was the best place to get a response. Both seem to be monitored!
Copy link to clipboard
Copied
Hm…
What is the purpose of coloring topEdgeStrokeColor and set topEdgeStrokeWeight to "0pt" ?
Hi Kai,
also test with tables that have no footer rows. 🙂
In that case I would do nothing. Otherwise you change the first row of a table.
main();
function main()
{
var allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for (var i = 0; i < allTables.length; i++) {
var curTable = allTables;
var numberOfFooterRows = curTable.footerRowCount;
// In case NO footer row is defined, do nothing and loop on:
if(numberOfFooterRows == 0){ continue };
// Otherwise you change topEdgeStrokeColor of the FIRST row of a table!
curTable.rows[-numberOfFooterRows].properties =
{
topEdgeStrokeColor : "CBOC Blue"
}
}
}
Regards,
Uwe
Copy link to clipboard
Copied
From what I can tell, in the Indesign table model, the bottomEdge of row
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@Laubender yes the answer and follow-on tips were very helpful.