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)
I cannot see from here, but make sure the blkrec.ObjectId is really a BlockTableRecord, but not the Model or Paper space.
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