Home General VB.NET Purge Block from Drawing
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Purge Block from Drawing PDF Print E-mail
User Rating: / 1
PoorBest 
Tutorials

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

 [code]Public Sub PurgeBlockMethod()Using db As Database = HostApplicationServices.WorkingDatabaseUsing tr As Transaction = db.TransactionManager.StartTransaction()Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.EditorTry

 

 

 

 

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.ValueDim idarr As ObjectId() = ss.GetObjectIds()Dim id As ObjectIdFor Each id In idarrDim e As Entity = CType(tr.GetObject(id, OpenMode.ForWrite, True), Entity)Next idEnd 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]

 

 

 

 

 

 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade