Skip to main content
Kasyan Servetsky
Legend
January 4, 2017
Answered

How to get reference to the first body row on page in a long table?

  • January 4, 2017
  • 2 replies
  • 18559 views

Dear forum,

I have a long table which is threaded among several text frames (pages). I want to get the reference to the first body row in each frame so that to check if it contains a product name. (I can do this by checking if all the cells in the row have been merged.)

Since a table looks like a single character for script, I don’t see a straightforward way to achieve my goal.

So far, I solved it in a sloppy way: I check the baseline of the 1st insertion point of the 1st cell in the row.

else if (RoundString(row.cells[0].insertionPoints[0].baseline, 1) == firstRowBaseline && mainRow != null) {

Is there a more elegant solution?

Thank you in advance!

Regards,
Kasyan

This topic has been closed for replies.

2 replies

Liphou
Inspiring
December 13, 2017

Merci

I'm on Mac, I do not know the command in Termibal.

For the error, it signals me that 'r' is 'undefined'.

I am especially curious to be able to use the 'Compare Functions.jsx' script

//---------------------------

Je suis sur Mac, je ne connais pas la commande en Termibal.

Pour l'erreur, il me signal que 'r' est 'undefined'.

Je suis surtout curieux de pouvoir réutilisé le script 'Compare Functions.jsx'

Trevor:
Trevor:Correct answer
Legend
January 4, 2017
Kasyan Servetsky
Legend
January 6, 2017

Hi Trevor,

Thank you very much for pointing me in the right direction!

I used the approach you used in your second script.

Here's the code in case someone is interested:

main();

function main() {

    var doc = app.activeDocument,

    table = doc.stories[1].tables[0];

    tableTest(table);

}

function tableTest(table) {

    var textFrame, previousTextFrame, currentTextFrame,

    rows = table.rows;

   

    previousTextFrame = rows[0].cells[0].insertionPoints[0].parentTextFrames[0];

    for (var i = 0; i < rows.length; i++) {

        row = rows;

        if (row.rowType != RowTypes.BODY_ROW) continue; // skip headers & footers

       

        currentTextFrame = row.cells[0].insertionPoints[0].parentTextFrames[0];

        // the first body row in the first frame, or text frame has changed

        if ((i - table.headerRowCount == 0 && currentTextFrame == previousTextFrame) || currentTextFrame != previousTextFrame) {

            row.fillColor = "Yellow";

        }

        else {

            row.fillColor = "Magenta";

        }

   

        previousTextFrame = currentTextFrame;

    }

}

Regards,
Kasyan

Trevor:
Legend
January 9, 2017

Hi Uwe,

In practice, using .everyItem().getElements() is not always faster than using collections.

I tested the script against the Test-Before.indd (the link to both is in a previous post) on my home PC a few times and it takes to complete:

4 secs with dynamic collection

5 secs with static array

Adding the 'Undo-Redo' feature is not a client's requirement; it's just a habit of mine. In this particular case, it didn't work for some reason. For pure academic interest, I'd like to know why.

Regards,

Kasyan


Hi Kasyan,

Try .everyItem().getElements().slice()

Adding the slice can make a significant difference with large collections.

I'm not saying it will. Also it avoids the [too many elements] error.

I just did a search on it and, regarding the performance it could be that it's only with older versions.

See Re: Get the index of the current page?

See also Re: Big performance issue while removing tabs by indents

Worth a go for the extra 8 characters.

Trevor