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