22 | 06 | 2017

Delete Blocks by Name

This functions looks up and delete all blocks by name.

{code lang:vbnet lines:false hidden:false}
Function DeleteBlock(ByVal BlockName As String)

'****************************************
'*** Code from VisibleVisual.com ********
'****************************************
Dim ent As AcadEntity
Dim oBkRef As AcadBlockReference
Dim Insertpoints As Variant

Dim A As Double
'First we go over every object in the modelspace
For Each ent In ThisDrawing.ModelSpace
'Check if the object is a block
If ent.ObjectName = "AcDbBlockReference" Then
Set oBkRef = ent
'If the object is a block then check if its the block we are looking for
If oBkRef.EffectiveName = BlockName Then
'Delete the Block
A = A + 1
oBkRef.Delete
End If
'Next object
End If
Next ent

End Function{/code}

Download the complete project below. The project is hooked to the count block tutorial. Just select a block from the list to delete it.

Login

Sign up now and upload your code to the website.

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