.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 2
Anonymous
1410 Views, 1 Reply

Purge block

I have a lot of experience in VB, but not in AutoCAD. How do I purge a block with VB commands.
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

Give that a try just change the block
name to your suit

Public Sub PurgeBlockMethod()
Using db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Try
Dim tv() As TypedValue = {New TypedValue(DxfCode.Start, "INSERT"), New TypedValue(DxfCode.BlockName, "MyBlock")}
Dim sf As SelectionFilter = New SelectionFilter(tv)
Dim psr As PromptSelectionResult = ed.SelectAll(sf)
If psr.Status = PromptStatus.OK Then

Dim ss As SelectionSet = psr.Value
Dim idarr As ObjectId() = ss.GetObjectIds()
Dim id As ObjectId
For Each id In idarr
Dim e As Entity = CType(tr.GetObject(id, OpenMode.ForWrite, True), Entity)
e.Erase()
Next id
End If
Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
If Not bt.Has("MyBlock") Then
MessageBox.Show("block MyBlock does not exist")
Return
End If
Dim btr As BlockTableRecord = tr.GetObject(bt("MyBlock"), OpenMode.ForWrite, True, True)
Dim idcoll As ObjectIdCollection = New ObjectIdCollection()
idcoll.Add(btr.ObjectId)
db.Purge(idcoll)
btr.Erase(True)
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MessageBox.Show(ex.StackTrace)
End Try
End Using
End Using
End Sub

~'J'~

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