Chobo,
您的代码在迭代选择集时从选择集中删除对象……这是不允许的。此外,在报告错误之前,您清除了错误处理程序中的错误,因此错误MsgBox中没有显示任何内容
我认为下面的代码实现了您的期望。我不知道';t喜欢使用SendCommand,但不去VL类,它';这是我现在唯一能想到的办法
- Option Explicit
- Sub ColorFilter()
- Dim objSelSet As AcadSelectionSet
- On Error Resume Next
- ThisDrawing.SelectionSets("sset").Delete
- On Error GoTo ErrHere
-
- Set objSelSet = ThisDrawing.SelectionSets.Add("sset")
- Dim intGcode(0) As Integer
- Dim varCodeData(0) As Variant
- intGcode(0) = 62
- varCodeData(0) = "40"
- objSelSet.Select acSelectionSetAll, , , intGcode, varCodeData
-
- Dim lngMax As Long
- Dim lngCnt As Long
- Dim objRemove() As AcadEntity
- Dim objEnt As AcadEntity
- Dim I As Integer
-
- lngMax = objSelSet.Count
- For lngCnt = 0 To lngMax - 1
- Set objEnt = objSelSet.Item(lngCnt)
- If objEnt.TrueColor.ColorMethod = acColorMethodByRGB Then
- ReDim Preserve objRemove(I)
- Set objRemove(I) = objEnt
- I = 1 + I
- End If
- Next
- objSelSet.RemoveItems objRemove
- If objSelSet.Count > 0 Then
- ThisDrawing.SendCommand "(setq ss (ssadd)) "
- For Each objEnt In objSelSet
- ThisDrawing.SendCommand "(ssadd (handent " & Chr(34) & objEnt.Handle & _
- Chr(34) & ") ss) "
- Next
- End If
- ThisDrawing.SendCommand "(sssetfirst nil ss) "
- objSelSet.Delete
- Exit Sub
-
- ErrHere:
- If Err Then
- MsgBox Err.Description
- Err.Clear
- End If
- End Sub
|