Message 1 of 8
Table not updating information

Not applicable
07-03-2010
08:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
I have been playing with tables in AutoCAD lately and have had mixed results. I can create a table from scratch using code and edit the table. However editing an existing table is a different story. The table will not update at the end with the new information or formatting. The code i have is as follows:
Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Try Dim selectionres As PromptSelectionResult selectionres = ed.SelectImplied If (selectionres.Status = PromptStatus.Error) Then Dim selectionopt As PromptSelectionOptions selectionopt = New PromptSelectionOptions selectionopt.MessageForAdding = vbCr + "Select Table to Edit " selectionres = ed.GetSelection(selectionopt) Else End If If selectionres.Status = PromptStatus.OK Then Dim tr As Transaction = doc.TransactionManager.StartTransaction() Using tr Dim ids As New ObjectIdCollection(selectionres.Value.GetObjectIds) Dim bt As BlockTable = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) For Each id As Object In ids Dim tb As Table = id.GetObject(OpenMode.ForWrite) Dim numrows As Integer Dim numcol As Integer numrows = tb.Rows.Count numcol = tb.Columns.Count ed.WriteMessage("table name: " + tb.Name.ToString + " Num Columns: " + numcol.ToString + " Num Rows: " + numrows.ToString) ' Use a nested loop to add and format each cell For i As Integer = 1 To numrows For j As Integer = 1 To numcol If tb.Cells(i, 1).Value = "1/1" Then 'tb.Cells(i, j).Borders.Bottom.IsVisible = False tb.Rows(i).Borders.Top.IsVisible = False ElseIf tb.Cells(i, 1).Value = "1/2" Then tb.Cells(i, 1).TextString = "new" Else End If tb.Cells(i, j).Alignment = CellAlignment.MiddleLeft Next Next tb.GenerateLayout() btr.AppendEntity(tb) 'tr.AddNewlyCreatedDBObject(tb, True) tr.Commit() Next End Using End If Catch ex As Exception End Try
The code seems pretty basic and hence i can't figure out what i'm missing. The plan is to get the table edit to work, then add more to the code that will edit the existing table.
any push in the right direction would be appreciated.