Author Topic: Adding Table to ModelSpace causes errors in drawing database  (Read 2804 times)

0 Members and 1 Guest are viewing this topic.

TJK44

  • Guest
Adding Table to ModelSpace causes errors in drawing database
« on: October 25, 2019, 11:06:06 AM »
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: [Select]
        <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
« Last Edit: October 25, 2019, 11:16:05 AM by TJK44 »

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Adding Table to ModelSpace causes errors in drawing database
« Reply #1 on: October 25, 2019, 12:55:00 PM »
Have tried putting the table code inside the transaction?
Not sure why or if it would help, but first gut feeling.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Adding Table to ModelSpace causes errors in drawing database
« Reply #2 on: October 26, 2019, 05:45:03 AM »
try table.recompute just before commit.
prefer size over NumRows, NumColumns.
tb.GenerateLayout() should be just after set size

TJK44

  • Guest
Re: Adding Table to ModelSpace causes errors in drawing database
« Reply #3 on: October 28, 2019, 01:58:16 PM »
Thank you It's Alive! Adding

Code - vb.net: [Select]
  1. tb.RecomputeTableBlock(True)

resolved the problem (weird).