weilly 发表于 2009-8-20 15:53:00

[求助]困惑???选择集的操作放在函数中无法选择!

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

雪山飞狐_lzh 发表于 2009-8-20 19:40:00

<p>你的函数呢?</p>
页: [1]
查看完整版本: [求助]困惑???选择集的操作放在函数中无法选择!