Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I target an Indesign Table footerRow in JavaScript

Explorer ,
Dec 10, 2017 Dec 10, 2017

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

TOPICS
Scripting
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Dec 10, 2017 Dec 10, 2017

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:

  • RowTypes.BODY_ROW
  • RowTypes.HEADER_ROW
  • RowTypes.FOOTER_ROW
  • RowTypes.MIXED_STATE

If it is 'footer row' you can calculate the first one using the table.footerRowCount property which, as th

...
Translate
Valorous Hero ,
Dec 10, 2017 Dec 10, 2017

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:

  • RowTypes.BODY_ROW
  • RowTypes.HEADER_ROW
  • RowTypes.FOOTER_ROW
  • RowTypes.MIXED_STATE

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 10, 2017 Dec 10, 2017

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

  • RowTypes.BODY_ROW
  • RowTypes.HEADER_ROW
  • RowTypes.FOOTER_ROW
  • RowTypes.MIXED_STATE

Thanks for pointing me in the right direction!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 11, 2017 Dec 11, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 11, 2017 Dec 11, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2017 Dec 11, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 11, 2017 Dec 11, 2017

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2017 Dec 11, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 11, 2017 Dec 11, 2017

From what I can tell, in the Indesign table model, the bottomEdge of row is "overlapped" by the the topEdge of row [n-1]. Styling one edge to 0pts was a way of killing any potential overlapping. Although guess I have it backwards. The bottomEdge should be 0pts and the topEdge should be .75pt.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2017 Dec 12, 2017

Hi Welshjs ,

did Kai's script with my added code solve your problem?

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 13, 2017 Dec 13, 2017
LATEST

@Laubender yes the answer and follow-on tips were very helpful.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines