参考: '------------------------------------------------------------------ Option Explicit
'------------------------------------------------------------------
Public Sub Sample() On Error GoTo ERROR_HANDLER
Dim ssetObj As AcadSelectionSet Set ssetObj = CreateSSet("MySelection")
Dim mode As Integer mode = acSelectionSetAll
Dim gpCode(0 To 10) As Integer Dim dataValue(0 To 10) As Variant
Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue
ssetObj.Select mode, , , groupCode, dataCode
MsgBox ssetObj.Count
Exit Sub ERROR_HANDLER: Debug.Print "Error In GetIntersectionPoints: " & Err.Number & ", " & Err.Description End Sub
'------------------------------------------------------------------ ' 创建选择集 '------------------------------------------------------------------ Private Function CreateSSet(ByVal name As String) As AcadSelectionSet On Error GoTo ERR_HANDLER
Dim ssetObj As AcadSelectionSet Dim SSetColl As AcadSelectionSets Set SSetColl = ThisDrawing.SelectionSets
Dim index As Integer Dim found As Boolean
found = False
For index = 0 To SSetColl.Count - 1 Set ssetObj = SSetColl.Item(index) If StrComp(ssetObj.name, name, 1) = 0 Then found = True Exit For End If Next
If Not (found) Then Set ssetObj = SSetColl.Add(name) Else ssetObj.Clear End If
Set CreateSSet = ssetObj
Exit Function ERR_HANDLER: Debug.Print "Error in sub CreateSSet: " & Err.Number & " -- "; Err.Description Resume ERR_END
Sub test() On Error Resume Next Dim ft, fd Dim ss As AcadSelectionSet ft = CreateArray(vbInteger, -4, -4, 0, 40, -4, -4, 0, 62, -4, -4) fd = CreateArray(vbVariant, "<or", "<and", "Circle", 1, "and>", "<and", "Line", 1, "and>", "or>") ThisDrawing.SelectionSets("TlsSS").Delete Set ss = ThisDrawing.SelectionSets.Add("TlsSS") ss.SelectOnScreen ft, fd End Sub
Function CreateArray(ByVal TypeName As VbVarType, ParamArray ValArray()) Dim i, mArray Dim nCount As Integer
nCount = UBound(ValArray)
Select Case TypeName Case vbDouble Dim dArray() As Double ReDim dArray(nCount) mArray = dArray Case vbInteger Dim nArray() As Integer ReDim nArray(nCount) mArray = nArray Case vbString Dim sArray() As String ReDim sArray(nCount) mArray = sArray Case vbVariant Dim vArray() ReDim vArray(nCount) mArray = vArray End Select
For i = 0 To nCount mArray(i) = ValArray(i) Next i