Place table using existing table style template (VB.net)

Place table using existing table style template (VB.net)

RodWing
Enthusiast Enthusiast
817 Views
4 Replies
Message 1 of 5

Place table using existing table style template (VB.net)

RodWing
Enthusiast
Enthusiast

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
0 Likes
818 Views
4 Replies
Replies (4)
Message 2 of 5

hgasty1001
Advisor
Advisor

Hi, 

 

Why the second transaction?, just delete the second transaction and commit the first transaction.

 

Gaston Nunez

0 Likes
Message 3 of 5

RodWing
Enthusiast
Enthusiast

@hgasty1001 wrote:

Hi, 

 

Why the second transaction?, just delete the second transaction and commit the first transaction.

 

Gaston Nunez


Gaston, Thanks for the reply.

 

The reason for the second transaction is that I actually have this broken apart in separate classes. I combined the code from the different functions to create this sub to more easily illustrate what I'm trying to accomplish.

 

0 Likes
Message 4 of 5

hgasty1001
Advisor
Advisor

Hi,

 

But then,  you have to commit the first transaction too. I use this to create a table:

 

1.-Start a transaction

2.-Instance a new table

3.-Asign style and properties

4.-Generate layout

5.-Add to DB

6.-Commit the transaction

 

 

Gaston Nunez

0 Likes
Message 5 of 5

SENL1362
Advisor
Advisor

Gaston,
I'll assume you assign the Styles (3.) separately to all the parts of the Instantiated table as i do.
In earlier experiments assigning the StyleId to the table didn't work for me either.

0 Likes