明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1057|回复: 1

VB+类模块CLS+SelectionSets的应用

[复制链接]
发表于 2008-8-16 22:00:00 | 显示全部楼层 |阅读模式

Dim xlsMdb As New XlsMdbTxtData
Dim CadEnt As New AcadEntity

'主程序
Private Sub Form_Load()
  Dim ojbLine As AcadLine
  Dim pp(0 To 2) As Double, ppp(0 To 2) As Double
  Dim xlSheet1 As Worksheet
  Set xlSheet1 = xlsMdb.ReturnxlSheet("Sheet1")
  Dim objText As AcadText, objTextSelectSet As AcadSelectionSet
  Dim fTypa As Variant, fData As Variant
  fType = Array("0"): fData = Array("Text")
  Set objTextSelectSet = CadEnt.ReturnAllSelectSet(fType, fData)
  Debug.Print objTextSelectSet.Count
  For ii = 0 To objTextSelectSet.Count - 1
    Set objText = objTextSelectSet.Item(ii)
    xlSheet1.Cells(ii + 1, 1) = objText.TextString
  Next ii
 
End Sub

'类模块

Function ReturnAllSelectSet(fTypeArray As Variant, fDataArray As Variant) As AcadSelectionSet
  Dim appAutoCAD As AutoCAD.AcadApplication
  On Error Resume Next
  Set appAutoCad = GetObject(, "AutoCAD.Application")
  If Err Then
    Err.Clear
    Set appAutoCad = CreateObject("AutoCAD.Application")
   
  End If
  appAutoCad.Visible = True
  Dim AcadDoc As AcadDocument
  Set AcadDoc = appAutoCad.ActiveDocument

''
    Dim fType, fData
    ReDim fType(0 To UBound(fTypeArray) + 2) As Integer
    ReDim fData(0 To UBound(fDataArray) + 2) As Variant
    fType(0) = -4
    For ii = 0 To UBound(fTypeArray)
      fType(ii + 1) = fTypeArray(ii)
    Next ii
    fType(UBound(fType)) = -4
    ''
    fData(0) = "<Or"
    For ii = 0 To UBound(fDataArray)
      fData(ii + 1) = fDataArray(ii)
    Next ii
    fData(UBound(fData)) = "Or>"
    ''
    '选择过滤出图形中所有的标注对象
''
  With AcadDoc
    .SelectionSets("mccad").Delete
    Set Sset = .SelectionSets.Add("mccad")
    '建立过滤器
    '选择过滤出图形中所有的标注对象
    Sset.Select 5, , , fType, fData
    Set ReturnAllSelectSet = Sset
  End With
 
End Function

 楼主| 发表于 2008-9-2 21:23:00 | 显示全部楼层

Sub LS()
  Dim rr As AcadSelectionSet
  Dim objText As AcadText
  fType = Array("0"): fData = Array("Text")
  Set rr = ReturnAllSelectSet(fType, fData)
  For ii = 0 To rr.Count - 1
    Select Case rr.Item(ii).ObjectName
      Case "AcDbText"
        Set objText = rr.Item(ii)
        With objText
          Debug.Print .TextString
        End With
    End Select
  Next ii
End Sub
Function ReturnAllSelectSet(fTypeArray As Variant, fDataArray As Variant) As AcadSelectionSet
  Dim appAutoCad As AutoCAD.AcadApplication
  On Error Resume Next
  Set appAutoCad = GetObject(, "AutoCAD.Application")
  If Err Then
    Err.Clear
    Set appAutoCad = CreateObject("AutoCAD.Application")
   
  End If
  appAutoCad.Visible = True
  Dim AcadDoc As AcadDocument
  Set AcadDoc = appAutoCad.ActiveDocument

''
    Dim fType, fData
    ReDim fType(0 To UBound(fTypeArray) + 2) As Integer
    ReDim fData(0 To UBound(fDataArray) + 2) As Variant
    fType(0) = -4
    For ii = 0 To UBound(fTypeArray)
      fType(ii + 1) = fTypeArray(ii)
    Next ii
    fType(UBound(fType)) = -4
    ''
    fData(0) = "<Or"
    For ii = 0 To UBound(fDataArray)
      fData(ii + 1) = fDataArray(ii)
    Next ii
    fData(UBound(fData)) = "Or>"
    ''
    '选择过滤出图形中所有的标注对象
''
  With AcadDoc
    .SelectionSets("mccad").Delete
    Set Sset = .SelectionSets.Add("mccad")
    '建立过滤器
    '选择过滤出图形中所有的标注对象
    Sset.Select 5, , , fType, fData
    Set ReturnAllSelectSet = Sset
  End With
 
End Function

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

本版积分规则

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

GMT+8, 2024-11-26 07:30 , Processed in 0.148897 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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