block id is not null but block will not insert

block id is not null but block will not insert

Bauron
Contributor Contributor
461 Views
2 Replies
Message 1 of 3

block id is not null but block will not insert

Bauron
Contributor
Contributor

I am trying to insert a block that already exists in the drawing. 

I am getting a value for the block id. 

I am using a msg box to post

However, when I try to insert the block 

I am getting an error that says the block id is null

 

blkbl = blktbul(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
MsgBox(blkrec.Name)

tblkid2 = blkrec.ObjectId
MsgBox(tblkid2.ToString & " tblkid2" & tblkid3.ToString)
blktbul.UpgradeOpen()
' blokrec = blktrnz.GetObject(lytbtbl.Item("blknm"), OpenMode.ForWrite)
tblkin = New BlockReference(inspnt, blkrec.ObjectId)
MsgBox(tblkin.BlockName.ToString)

 

 

0 Likes
462 Views
2 Replies
Replies (2)
Message 2 of 3

augusto.goncalves
Alumni
Alumni

I cannot see from here, but make sure the blkrec.ObjectId is really a BlockTableRecord, but not the Model or Paper space.

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 3

Anonymous
Not applicable

We really need to see more of your code to help, but from what you did post, i would say you need a transaction, here's a little block insertion snippet for reference:

 Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                Dim id As ObjectId = bt("YourBlockNameHere")
                Dim ppo As New PromptPointOptions(vbCrLf & "Specify insertion point:")
                Dim ppr As PromptPointResult = ed.GetPoint(ppo)
                If ppr.Status = PromptStatus.OK Then
                    Dim pts As Point3d = ppr.Value
                    Dim br As New BlockReference(pts, id)
                    Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
                    btr.AppendEntity(br)
                    tr.AddNewlyCreatedDBObject(br, True)
                    tr.Commit()
                End If
            End Using

 

 

0 Likes