Code Red > .NET

Adding Table to ModelSpace causes errors in drawing database

(1/1)

TJK44:
I'm having a strange issue with a drawing file when adding a table (very simple table) to modelspace. After the command runs and I run an audit on the drawing, it returns an error related to the new table that was generated...


AcDbTable(10199A4)         BTR Id invalid               
AcDbTable(10199A4)                was not repaired.   

however, as soon as I move the table at all within the modelspace, the error goes away. Anyone ever have this issue, know what is going on? The below code is how I am generating a table, for test purposes. Very simple way of adding a table, but it generates the above error each time. I don't understand how the error BTR Id invalid occurs when the table is first generated, but when it is moved at all, the error fixes itself?


--- Code: ---        <CommandMethod("tabletest")>
        Public Sub tabletest()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Dim pr As PromptPointResult = ed.GetPoint("Enter insertion point: ")
            If pr.Status = PromptStatus.OK Then
                Dim tb As New Table()
                tb.TableStyle = db.Tablestyle
                tb.NumRows = 1
                tb.NumColumns = 1
                tb.SetRowHeight(3)
                tb.SetColumnWidth(15)
                tb.Position = pr.Value

                tb.SetTextHeight(0, 0, 1)
                tb.SetTextString(0, 0, "test")
                tb.SetAlignment(0, 0, CellAlignment.MiddleCenter)

                tb.GenerateLayout()

                Using tr As Transaction = db.TransactionManager.StartTransaction()
                    Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
                    Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
                    btr.AppendEntity(tb)
                    tr.AddNewlyCreatedDBObject(tb, True)
                    tr.Commit()
                End Using
            End If
        End Sub

--- End code ---

Jeff H:
Have tried putting the table code inside the transaction?
Not sure why or if it would help, but first gut feeling.

It's Alive!:
try table.recompute just before commit.
prefer size over NumRows, NumColumns.
tb.GenerateLayout() should be just after set size

TJK44:
Thank you It's Alive! Adding


--- Code - vb.net: ---tb.RecomputeTableBlock(True)
resolved the problem (weird).

Navigation

[0] Message Index

Go to full version