Use SelectionSet and its powerful filtering and Erase methods
- Sub DeleteElements() Dim delSset As AcadSelectionSet On Error Resume Next Set delSset = ThisDrawing.SelectionSets.Add("Deletion") On Error GoTo 0 If delSset Is Nothing Then Set delSset = ThisDrawing.SelectionSets.Item("Deletion") Dim gpCode(0 to 2) As Integer Dim dataValue(0 to 2) As Variant gpCode(0) = 0 : dataValue(0) = "LINE" ' filter on line elements only gpCode(1) = 8 : dataValue(1) = "myLayerName" ' filter on given layer gpCode(2) = 62 : dataValue(2) = 1 ' filter on color (1 is the red color dataValue) With delSset .Clear .Select acSelectionSetAll, , , gpCode, dataValue If .Count > 0 Then .Erase End WithEnd Sub
|