明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4050|回复: 2

用VBA怎样选择一个图层的所有内容??

[复制链接]
发表于 2005-8-17 08:24 | 显示全部楼层 |阅读模式
用VBA怎样选择一个图层的所有内容??请高手给个具体例子!!
发表于 2009-2-7 12:10 | 显示全部楼层
我也正想解决这个问题呢。。。

发表于 2009-2-7 23:44 | 显示全部楼层

'****************创建带过滤器的选择集Start******************"

'创建过滤集
Public Sub BuildFilter(ByRef TypeArray, ByRef DataArray, ByRef gCodes() As Variant)
    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 ByVal 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
 
  'ParamArray定义的的数组在SUB内不能再做为实参传递
Public Sub BuildFilterAndCteSset(sset, ssName, ParamArray gCodes())
  '定义过滤器
  Dim pType, pData
  Dim codes() As Variant
 
  codes = gCodes
  BuildFilter pType, pData, codes
 
  '定义选择集
  Set sset = CreateSelectionSet(ssName)
 
  '根据以上指定的过滤器建立选择集
  sset.Clear
  sset.Select acSelectionSetAll, , , pType, pData
  '这里可以通过Select、SelectAtPoint、SelectByPolygon、SelectOnScreen等方法
  '配合Mode和Point1、Point2建立更加用户化的选择集
 
End Sub
'********************创建带过滤集的选择集end********************"

'应用实例

'通过在CAD命令行输入:(entget(car(entsel)))获取的对象基本特性

Public Sub LayerSS()
    Dim sset As AcadSelectionSet
    BuildFilterAndCteSset sset, "ss", 8, "层名"  
End Sub

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

本版积分规则

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

GMT+8, 2024-4-25 06:26 , Processed in 0.149441 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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