cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Translate the entire conversation x

Jlink InsertRow drawing table

ptc-5132323
8-Gravel

Jlink InsertRow drawing table

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);
    }
}
1 REPLY 1

Hi @ptc-5132323 

Thank you for your question. 

Your post appears well documented but has not yet received any response. I am replying to raise awareness. Hopefully, another community member will be able to help.

Also, feel free to add any additional information you think might be relevant. It sometimes helps to have screenshots to better understand what you are trying to do.

 

Best regards,


Catalina
PTC Community Moderator
PTC
Announcements

Top Tags