注意Dim entobj(2) As Variant这里有误。
程序可以这样写:
- Private Sub lick()
- Dim ssetobj As AcadSelectionSet
- Dim i As Integer
- Dim regions As Variant
- Dim entobj() As AcadEntity
- Dim ssetcount As Integer
- If ThisDrawing.SelectionSets.Count <> 0 Then
- For i = 0 To ThisDrawing.SelectionSets.Count - 1
- Set ssetobj = ThisDrawing.SelectionSets.Item(i)
- ssetobj.Delete
- Next
- End If
- Set ssetobj = ThisDrawing.SelectionSets.Add("test")
- ssetobj.SelectOnScreen
- ssetcount = ssetobj.Count
- ReDim entobj(ssetcount - 1) As AcadEntity
- For i = 0 To ssetcount - 1
- Set entobj(i) = ssetobj.Item(i)
- 'MsgBox "选择集的图元名称为:" & entobj(i).ObjectName
- Next
- regions = ThisDrawing.ModelSpace.AddRegion(entobj)
- End Sub
|