- Sub DelLayEnt()
- Dim LayerName As String
- LayerName = "0" '这里保存着要删除的图层名称
- Dim ss As AcadSelectionSet
- Set ss = CreateSelectionSet()
- Dim fType As Variant
- Dim fDate As Variant
- BuildFilter fType, fData, 8, LayerName
- ss.Select acSelectionSetAll, , , fType, fData
- Dim Ent As AcadEntity
- For Each Ent In ss
- Ent.Delete
- Next
- Update
- Debug.Print "所有在图层" & LayerName & "上的对象都已经被删除了。"
- End Sub
- Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())
- Dim fType() As Integer, fData()
- Dim index As Long, i As Long
-
- index = LBound(gCodes) - 1
-
- For i = LBound(gCodes) To UBound(gCodes) Step 2
- index = index + 1
- ReDim Preserve fType(0 To index)
- ReDim Preserve fData(0 To index)
- fType(index) = CInt(gCodes(i))
- fData(index) = gCodes(i + 1)
- Next
- typeArray = fType: dataArray = fData
- End Sub
- Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet
- Dim ss As AcadSelectionSet
-
- On Error Resume Next
- Set ss = ThisDrawing.SelectionSets(ssName)
- If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
- ss.Clear
- Set CreateSelectionSet = ss
- End Function
|