这是在网上看到的,介绍如何修正这种选择。但我试过之后,还是没有效果。
程序中的注释是我自己添加的,大家可以参考一下。
- Private Declare Function GetCursor Lib "user32" () As Long
-
- Public Function SelectOnScreenFix() As AcadSelectionSet
- Dim objSelSet As AcadSelectionSet
- Dim objSelCol As AcadSelectionSets
- Dim intCnt As Integer
- Dim objEnts() As AcadEntity
-
- On Error GoTo Err_Control
- ' 创建选择集
- Set objSelCol = ThisDrawing.SelectionSets
- For Each objSelSet In objSelCol
- If objSelSet.Name = "sos" Then
- objSelCol.Item("sos").Delete
- Exit For
- End If
- Next
- Set objSelSet = objSelCol.Add("sos")
-
- ' 当 GetCursor = 0 时,表示正常退出
- ' 当 GetCursor = 65553 时,表示执行平移、缩放等操作
- Do
- objSelSet.SelectOnScreen
- If GetCursor = 2822 Then ' 这儿有出入,实际测试时为65553
- ' 这儿也有疑问,执行其它操作时选择集中的实体还没真正产生,因而它的数目为0
- For intCnt = 0 To ThisDrawing.ActiveSelectionSet.Count - 1
- ReDim Preserve objEnts(intCnt)
- Set objEnts(intCnt) = ThisDrawing.ActiveSelectionSet(intCnt)
- Next intCnt
- objSelSet.AddItems objEnts
- End If
- Loop Until GetCursor = 0
- Set SelectOnScreenFix = objSelSet
-
- Exit_Here:
- Exit Function
-
- Err_Control:
- Select Case Err.Number
- Case Else
- MsgBox Err.Description
- End Select
- End Function
|