明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1168|回复: 1

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

[复制链接]
发表于 2009-8-20 15:53:00 | 显示全部楼层 |阅读模式

编程实现多边形选择集选择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

发表于 2009-8-20 19:40:00 | 显示全部楼层

你的函数呢?

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 00:53 , Processed in 0.162781 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表