Message 1 of 5
Place table using existing table style template (VB.net)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to place a table using an existing table style that has 26 rows and 7 columns with the column header text defined. When I manually place a new table using that style it is placed as designed. Trying to place a new table using that style using the Sub below I don't get any of the formatting. It places a 1x1 table. Checking the proprties of the 1x1 table it lists the correct table style.
What am I missing?
Thanks.
Sub PlaceTableTemplate(ByVal tsName As String)
Dim doc As Document
Dim db As Database
doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
db = doc.Database
Dim tsID As ObjectId
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim stDict As DBDictionary = tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForRead)
If stDict.Contains(tsName) Then
tsID = stDict.GetAt(tsName)
Else
MsgBox("Table style not found")
Exit Sub
End If
End Using
Dim ed As Editor
Dim pr As PromptPointResult
Dim tb As New Table
ed = doc.Editor
pr = ed.GetPoint(vbCrLf & "Enter table insertion point: ")
If pr.Status = PromptStatus.OK Then
With tb
.TableStyle = tsID
.Position = pr.Value
End With
Else
Exit Sub
End If
tb.GenerateLayout()
Using tr As Transaction = doc.TransactionManager.StartTransaction
Dim bt As BlockTable = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
btr.AppendEntity(tb)
tr.AddNewlyCreatedDBObject(tb, True)
tr.Commit()
End Using
End Sub