.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

block id is not null but block will not insert

2 REPLIES 2
Reply
Message 1 of 3
Bauron
360 Views, 2 Replies

block id is not null but block will not insert

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)

 

 

Tags (1)
2 REPLIES 2
Message 2 of 3
augusto.goncalves
in reply to: Bauron

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
Message 3 of 3
conormccartney3897
in reply to: Bauron

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

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost