I am looking for a way to search in a drawing for a table with the first cell has the content "Rev." and if this table is found, a new table should be added.
Below script finds the table, but it seems my command table.InsertRow() seems to be failing.
Can somebody help me?
(The table has 4 columns, if this has any influence.)
function addRowToRevTables(drawing) {
try {
// Get all tables in the drawing
var tables = drawing.ListTables();
for (var i = 0; i < tables.Count; i++) {
var table = tables.Item(i);
try {
// Get text from cell(1,1)
var cell = pfcCreate("pfcTableCell").Create(1, 1);
var mode = pfcCreate("pfcParamMode").DWGTABLE_NORMAL;
var textSeqs = table.GetText(cell, mode);
var note = textSeqs.Item(0);
if (textSeqs !== void null && textSeqs.Count > 0) {
// var cellText = textSeqs.Item(0).Get(0);
if (note == "Rev.") {
// alert("Value is:"+note);
// Add a new row at the bottom of this table
var lastRow = table.GetRowCount();
alert(lastRow);
table.InsertRow();
alert(note);
// table.InsertRow(1, lastRow); // row height = 1.0
// (optional) initialize new row with blank cells
// var colCount = table.GetColumnCount();
// for (var c = 1; c <= colCount; c++) {
// writeTextInCell(table, lastRow + 1, c, ".");
// }
alert("Added row to table with 'Rev.' in cell(1,1).");
}
}
} catch (addRowErr) {
// Skip tables where cell(1,1) doesn't exist
// alert("Inner Error: " + addRowErr.description);
}
}
} catch (generalErr) {
alert("Error: " + generalErr.message);
}
}