I'm doing some processing of multiple paragraphs. If any of them is a table, I need to save it in an array for handling after I'm done with the other paragraphs (so the paragraph count of the selection doesn't change while I'm iterating through it).
This seems to work; but when I iterate through the table array, all of the Table objects in it are "invalid." I've even checked the constructor name of each, and found it is "Table." So WTH? The code is below (and WTH Adobe, why don't you fix the "code" formatting option in the editor on this page? How many times do we have to bring this up?).
paras = app.selection[0].paragraphs;
var lastParaType = "";
var emptyParas = []; // Keep track of empty paragraphs to remove.
var tablesToProcess = []; // Keep track of tables (probably notes) to deal with.
for(paraIndex = 0; paraIndex < paras.length; paraIndex++)
{
currPara = paras.item(paraIndex);
if(currPara.tables.length > 0)
{
for(i = 0; i < currPara.tables.length; i++)
{
tablesToProcess.push(currPara.tables.item(i));
alert("This table is valid? " + currPara.tables.item(i).isValid); <---- RETURNS TRUE
}
}
....
}
And then after handling the other paragraphs:
if(tablesToProcess.length > 0)
{
alert("Tables to process: " + tablesToProcess.length);
alert("Table is " + tablesToProcess[0].isValid);
}
This shows the expected number of tables in my test case, but the second line returns false. Any action on the second line fails with "invalid object" despite my not having removed any paragraphs yet.