编程实现多边形选择集选择CAD实体,选择集的建立以及实体的选择通过函数实现,多边形的点通过函数的参数传递,但是函数中选择集始终为空。但是,同样的函数,不使用函数的话,选择集就可以选择,请问各位高手是什么原因。函数代码如下: Sub Example_SelectByPolygon() ' This example adds objects to a selection set by defining a polygon. Dim pt1, pt2, pt3, pt4 As Variant pt1 = ThisDrawing.Utility.GetPoint(, " 1") pt2 = ThisDrawing.Utility.GetPoint(, " 2") pt3 = ThisDrawing.Utility.GetPoint(, " 3") pt4 = ThisDrawing.Utility.GetPoint(, " 4") Dim ssetObj As AcadSelectionSet If Not IsNull(ThisDrawing.SelectionSets.Item("TEST_SSET2")) Then Set ssetObj = ThisDrawing.SelectionSets.Item("TEST_SSET2") ssetObj.Delete '及时删除不用的选择集非常重要 End If Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET2") ' Add to the selection set all the objects that lie within a fence Dim mode As Integer Dim pointsArray(0 To 11) As Double mode = acSelectionSetWindowPolygon pointsArray(0) = pt1(0): pointsArray(1) = pt1(1): pointsArray(2) = pt1(2) pointsArray(3) = pt2(0): pointsArray(4) = pt2(1): pointsArray(5) = pt2(2) pointsArray(6) = pt3(0): pointsArray(7) = pt3(1): pointsArray(8) = pt3(2) pointsArray(9) = pt4(0): pointsArray(10) = pt4(1): pointsArray(11) = pt4(2) ssetObj.SelectByPolygon mode, pointsArray ' Add to the selection set all the Circles that lie within fence ReDim gpCode(0 To 1) As Integer gpCode(0) = 0 gpCode(1) = 10 Dim pnt(0 To 2) As Double pnt(0) = 3: pnt(1) = 6: pnt(2) = 0 ReDim dataValue(0 To 1) As Variant dataValue(0) = "Circle" dataValue(1) = pnt Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue ssetObj.SelectByPolygon mode, pointsArray, groupCode, dataCode Dim element As AcadEntity For Each element In ssetObj element.Delete Next End Sub 可以选择 Sub Example_SelectByPolygon( pt1, pt2, pt3, pt4 As Variant) ' This example adds objects to a selection set by defining a polygon. Dim ssetObj As AcadSelectionSet If Not IsNull(ThisDrawing.SelectionSets.Item("TEST_SSET2")) Then Set ssetObj = ThisDrawing.SelectionSets.Item("TEST_SSET2") ssetObj.Delete '及时删除不用的选择集非常重要 End If Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET2") ' Add to the selection set all the objects that lie within a fence Dim mode As Integer Dim pointsArray(0 To 11) As Double mode = acSelectionSetWindowPolygon pointsArray(0) = pt1(0): pointsArray(1) = pt1(1): pointsArray(2) = pt1(2) pointsArray(3) = pt2(0): pointsArray(4) = pt2(1): pointsArray(5) = pt2(2) pointsArray(6) = pt3(0): pointsArray(7) = pt3(1): pointsArray(8) = pt3(2) pointsArray(9) = pt4(0): pointsArray(10) = pt4(1): pointsArray(11) = pt4(2) ssetObj.SelectByPolygon mode, pointsArray ' Add to the selection set all the Circles that lie within fence ReDim gpCode(0 To 1) As Integer gpCode(0) = 0 gpCode(1) = 10 Dim pnt(0 To 2) As Double pnt(0) = 3: pnt(1) = 6: pnt(2) = 0 ReDim dataValue(0 To 1) As Variant dataValue(0) = "Circle" dataValue(1) = pnt Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue ssetObj.SelectByPolygon mode, pointsArray, groupCode, dataCode Dim element As AcadEntity For Each element In ssetObj element.Delete Next End Sub
|