26 | 02 | 2017

Purge Block from Drawing

 Use the code below to purge a block from a drawing. Change  BLOCKNAME into the block you would like to purge

 

Public Sub PurgeBlockMethod()Using 

db As Database = HostApplicationServices.WorkingDatabase

Using tr As Transaction = db.TransactionManager.StartTransaction()

Dim ed As Editor = Autodesk.AutoCAD.Application

Services.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
 
e.Erase()

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)

Next id

End If
 

Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)

If Not bt.Has("BLOCKNAME") Then

MessageBox.Show("block does not exist")

Return
 

End If


idcoll.Add(btr.ObjectId)

db.Purge(idcoll)

btr.Erase(

tr.Commit()

MessageBox.Show(ex.StackTrace)
 
Dim btr As BlockTableRecord = tr.GetObject(bt("BLOCKNAME"), OpenMode.ForWrite, True, True)

Dim idcoll As ObjectIdCollection = New ObjectIdCollection()True)

Catch ex As Autodesk.AutoCAD.Runtime.ExceptionEnd Try
 

End Using

End Using

End Sub

Code from www.visiblevisual.com


 

 

 

 

Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2179684
Latest Articles