Problem with NextTblInDoc

Advocate ,
Feb 23, 2021

Copy link to clipboard

Copied

  • Dear friends,
    My test document has no reference pages, only master and body pages. There are 5 tables on the body pages.
  • The first table is 2 x 2 and in cell 1 the background is magenta (which is what is checked for).
  • This cell is found
  • Re-entering the while-loop after changing obj to obj.NextCellInTbl lets it run to the end of the table
  • This is detected and the script should enter the first cell of the next table for further search.
  • The log lists this:
«Table #1»        cell 1 which was found
«Table #1»        cell skipped 
«Table #1»        cell skipped
«Table #1»        last cell in table
«»                next "table"

This is not the complete script, just the relevant parts.

obj = oDoc.FirstTblInDoc.FirstRowInTbl.FirstCellInRow;
while (obj.ObjectValid()) {
  $.writeln("«" + obj.CellRow.RowTbl.UserString + "»");
  if (CompareColour(obj.CellOverrideShading, kReserved, sColour)) {
    break;
  } else {
    obj = obj.NextCellInTbl;
    if (!obj.ObjectValid()) { // end of table ?
      oRow = obj.CellRow;
      oTbl = oRow.RowTbl.NextTblInDoc; // look for next table
      $.writeln("«" + obj.CellRow.RowTbl.UserString + "»");
      if (oTbl.ObjectValid()) {
        obj = oTbl.FirstRowInTbl.FirstCellInRow;
        continue; // restart search for relevant cell
      }
    }
  }
}

Why do I not enter the second table?

And BTW there is no non-scripted method to set the user string...

TOPICS
Scripting

Views

29

Likes

Translate

Translate

Report

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

1 Correct Answer

Adobe Community Professional , Feb 23, 2021
frameexpert Adobe Community Professional , Feb 23, 2021
if (!obj.ObjectValid()) { // end of table ? oRow = obj.CellRow; If obj is no longer valid (first line) then the second line won't work.

Likes

Translate

Translate
Jump to answer Jump to answer
Adobe Community Professional ,
Feb 23, 2021

Copy link to clipboard

Copied

    if (!obj.ObjectValid()) { // end of table ?
      oRow = obj.CellRow;

If obj is no longer valid (first line) then the second line won't work.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
K.Daube AUTHOR LATEST
Advocate ,
Feb 23, 2021

Copy link to clipboard

Copied

Thanks Rick,

Yes, by the time I became blind at least on one eye...

This seems to work as expected:

while (obj.ObjectValid()) {
  if (CompareColour(obj.CellOverrideShading, kReserved, sColour)) {
    break;
  } else {
    oRow = obj.CellRow;
    oTbl = oRow.RowTbl.NextTblInDoc;          // look for next table prophylactivally
    if (obj.NextCellInTbl.ObjectValid()) {
      obj = obj.NextCellInTbl;
    } else {                                  // need go to next table
      obj = oTbl.FirstRowInTbl.FirstCellInRow;// restart search for relevant cell
    }
  }
}

 

Likes

Translate

Translate

Report

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