乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 85|回复: 5

关于SelecOnScreen的问题求教,急!

[复制链接]

2

主题

4

帖子

1

银币

初来乍到

Rank: 1

铜币
12
发表于 2008-5-27 08:25:00 | 显示全部楼层 |阅读模式
最近学习VBA遇到了些困难,
其中有一个,当我试图在模块里建立一个Sub过程时:代码如下:
Sub Example_SelectOnScreen()
        
    ' Create the selection set
    Dim ssetObj As AcadSelectionSet
    Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")
   
    ' Add objects to a selection set by prompting user to select on the screen
    ssetObj.SelectOnScreen
   
End Sub问题出现在只能运行一次,运行第二次的时候就回出现"命名选择集已存在"的错误,研究了一天也没改出来,请高手指教啊
回复

使用道具 举报

3

主题

11

帖子

5

银币

初来乍到

Rank: 1

铜币
23
发表于 2008-5-27 09:28:00 | 显示全部楼层
修改为如下试试:
Dim ssetObj As AcadSelectionSet
    on error resume netx
    Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")
    if err>0 then
      ThisDrawing.SelectionSets.delete("TEST_SSET")
      Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")
   endif

    ' Add objects to a selection set by prompting user to select on the screen
    ssetObj.SelectOnScreen
回复

使用道具 举报

2

主题

4

帖子

1

银币

初来乍到

Rank: 1

铜币
12
发表于 2008-5-27 09:47:00 | 显示全部楼层
谢谢楼上的回复!
不过好象其中的:ThisDrawing.SelectionSets.delete("TEST_SSET")
有点问题啊,SelectionSets本身并没有Delete方法啊

回复

使用道具 举报

4

主题

30

帖子

1

银币

初来乍到

Rank: 1

铜币
46
发表于 2008-5-27 10:38:00 | 显示全部楼层
'创建安全选择集
    If Not IsNull(ThisDrawing.SelectionSets.Item("SS5")) Then
        Set sstext = ThisDrawing.SelectionSets.Item("SS5")
        sstext.Delete
    End If
   Set sstext = ThisDrawing.SelectionSets.Add("SS5")
按这种方式设置选择集就行了。
回复

使用道具 举报

2

主题

4

帖子

1

银币

初来乍到

Rank: 1

铜币
12
发表于 2008-5-27 12:15:00 | 显示全部楼层
问题已经解决 ,多谢谢两位不吝赐教!
明道真是个好地方!
回复

使用道具 举报

15

主题

70

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
130
发表于 2008-5-30 08:23:00 | 显示全部楼层
因为运行一次,选择集TEST_SSET已经存在,可以使用如下办法:
'创建过滤器的函数
Public Sub BuildFilter(TypeArray, dataArray, ParamArray gCodes())
    Dim fType() As Integer, fData()
    Dim index As Long, i As Long
   
    index = LBound(gCodes) - 1
    For i = LBound(gCodes) To UBound(gCodes) Step 2
        index = index + 1
        ReDim Preserve fType(0 To index)
        ReDim Preserve fData(0 To index)
        fType(index) = CInt(gCodes(i))
        fData(index) = gCodes(i + 1)
    Next
    TypeArray = fType: dataArray = fData
   
End Sub
'创建空间选择集的函数
Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet
    Dim ss As AcadSelectionSet
    On Error Resume Next
    Set ss = ThisDrawing.SelectionSets(ssName)
    If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
    ss.Clear
    Set CreateSelectionSet = ss
End Function
'返回Thisdrawing,使用CreateSelectionSet和BuildFilter
  '定义空白选择集
  Dim LwPSelSet As AcadSelectionSet
  Set LwPSelSet = CreateSelectionSet
  
      
    '建立选择集过滤器
  Dim TypeArray As Variant
  Dim DateArray As Variant
  BuildFilter TypeArray, DateArray, 0, "LWPOLYLINE", 8, "jmd"
  '0 是类型  8是图层
  LwPSelSet.SelectOnScreen TypeArray, DateArray  ’其中TypeArray和DateArray是可选项
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-4 17:43 , Processed in 0.532647 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表