兰州人 发表于 2008-8-16 22:00:00

VB+类模块CLS+SelectionSets的应用

<p>Dim xlsMdb As New XlsMdbTxtData<br/>Dim CadEnt As New AcadEntity</p><p>'主程序<br/>Private Sub Form_Load()<br/>&nbsp; Dim ojbLine As AcadLine<br/>&nbsp; Dim pp(0 To 2) As Double, ppp(0 To 2) As Double<br/>&nbsp; Dim xlSheet1 As Worksheet<br/>&nbsp; Set xlSheet1 = xlsMdb.ReturnxlSheet("Sheet1")<br/>&nbsp; Dim objText As AcadText, objTextSelectSet As AcadSelectionSet<br/>&nbsp; Dim fTypa As Variant, fData As Variant<br/>&nbsp; fType = Array("0"): fData = Array("Text")<br/>&nbsp; Set objTextSelectSet = CadEnt.ReturnAllSelectSet(fType, fData)<br/>&nbsp; Debug.Print objTextSelectSet.Count<br/>&nbsp; For ii = 0 To objTextSelectSet.Count - 1<br/>&nbsp;&nbsp;&nbsp; Set objText = objTextSelectSet.Item(ii)<br/>&nbsp;&nbsp;&nbsp; xlSheet1.Cells(ii + 1, 1) = objText.TextString<br/>&nbsp; Next ii<br/>&nbsp; <br/>End Sub<br/></p><p>'类模块</p><p>Function ReturnAllSelectSet(fTypeArray As Variant, fDataArray As Variant) As AcadSelectionSet<br/>&nbsp; Dim appAutoCad As AutoCAD.AcadApplication<br/>&nbsp; On Error Resume Next<br/>&nbsp; Set appAutoCad = GetObject(, "AutoCAD.Application")<br/>&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp; Set appAutoCad = CreateObject("AutoCAD.Application")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp; End If<br/>&nbsp; appAutoCad.Visible = True<br/>&nbsp; Dim AcadDoc As AcadDocument<br/>&nbsp; Set AcadDoc = appAutoCad.ActiveDocument</p><p>''<br/>&nbsp;&nbsp;&nbsp; Dim fType, fData<br/>&nbsp;&nbsp;&nbsp; ReDim fType(0 To UBound(fTypeArray) + 2) As Integer<br/>&nbsp;&nbsp;&nbsp; ReDim fData(0 To UBound(fDataArray) + 2) As Variant<br/>&nbsp;&nbsp;&nbsp; fType(0) = -4<br/>&nbsp;&nbsp;&nbsp; For ii = 0 To UBound(fTypeArray)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fType(ii + 1) = fTypeArray(ii)<br/>&nbsp;&nbsp;&nbsp; Next ii<br/>&nbsp;&nbsp;&nbsp; fType(UBound(fType)) = -4<br/>&nbsp;&nbsp;&nbsp; ''<br/>&nbsp;&nbsp;&nbsp; fData(0) = "&lt;Or"<br/>&nbsp;&nbsp;&nbsp; For ii = 0 To UBound(fDataArray)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fData(ii + 1) = fDataArray(ii)<br/>&nbsp;&nbsp;&nbsp; Next ii<br/>&nbsp;&nbsp;&nbsp; fData(UBound(fData)) = "Or&gt;"<br/>&nbsp;&nbsp;&nbsp; ''<br/>&nbsp;&nbsp;&nbsp; '选择过滤出图形中所有的标注对象<br/>''<br/>&nbsp; With AcadDoc<br/>&nbsp;&nbsp;&nbsp; .SelectionSets("mccad").Delete<br/>&nbsp;&nbsp;&nbsp; Set Sset = .SelectionSets.Add("mccad")<br/>&nbsp;&nbsp;&nbsp; '建立过滤器<br/>&nbsp;&nbsp;&nbsp; '选择过滤出图形中所有的标注对象<br/>&nbsp;&nbsp;&nbsp; Sset.Select 5, , , fType, fData<br/>&nbsp;&nbsp;&nbsp; Set ReturnAllSelectSet = Sset<br/>&nbsp; End With<br/>&nbsp; <br/>End Function</p>

兰州人 发表于 2008-9-2 21:23:00

<p>Sub LS()<br/>&nbsp; Dim rr As AcadSelectionSet<br/>&nbsp; Dim objText As AcadText<br/>&nbsp; fType = Array("0"): fData = Array("Text")<br/>&nbsp; Set rr = ReturnAllSelectSet(fType, fData)<br/>&nbsp; For ii = 0 To rr.Count - 1<br/>&nbsp;&nbsp;&nbsp; Select Case rr.Item(ii).ObjectName<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case "AcDbText"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objText = rr.Item(ii)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; With objText<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print .TextString<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End With<br/>&nbsp;&nbsp;&nbsp; End Select<br/>&nbsp; Next ii<br/>End Sub<br/>Function ReturnAllSelectSet(fTypeArray As Variant, fDataArray As Variant) As AcadSelectionSet<br/>&nbsp; Dim appAutoCad As AutoCAD.AcadApplication<br/>&nbsp; On Error Resume Next<br/>&nbsp; Set appAutoCad = GetObject(, "AutoCAD.Application")<br/>&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp; Set appAutoCad = CreateObject("AutoCAD.Application")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp; End If<br/>&nbsp; appAutoCad.Visible = True<br/>&nbsp; Dim AcadDoc As AcadDocument<br/>&nbsp; Set AcadDoc = appAutoCad.ActiveDocument</p><p>''<br/>&nbsp;&nbsp;&nbsp; Dim fType, fData<br/>&nbsp;&nbsp;&nbsp; ReDim fType(0 To UBound(fTypeArray) + 2) As Integer<br/>&nbsp;&nbsp;&nbsp; ReDim fData(0 To UBound(fDataArray) + 2) As Variant<br/>&nbsp;&nbsp;&nbsp; fType(0) = -4<br/>&nbsp;&nbsp;&nbsp; For ii = 0 To UBound(fTypeArray)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fType(ii + 1) = fTypeArray(ii)<br/>&nbsp;&nbsp;&nbsp; Next ii<br/>&nbsp;&nbsp;&nbsp; fType(UBound(fType)) = -4<br/>&nbsp;&nbsp;&nbsp; ''<br/>&nbsp;&nbsp;&nbsp; fData(0) = "&lt;Or"<br/>&nbsp;&nbsp;&nbsp; For ii = 0 To UBound(fDataArray)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fData(ii + 1) = fDataArray(ii)<br/>&nbsp;&nbsp;&nbsp; Next ii<br/>&nbsp;&nbsp;&nbsp; fData(UBound(fData)) = "Or&gt;"<br/>&nbsp;&nbsp;&nbsp; ''<br/>&nbsp;&nbsp;&nbsp; '选择过滤出图形中所有的标注对象<br/>''<br/>&nbsp; With AcadDoc<br/>&nbsp;&nbsp;&nbsp; .SelectionSets("mccad").Delete<br/>&nbsp;&nbsp;&nbsp; Set Sset = .SelectionSets.Add("mccad")<br/>&nbsp;&nbsp;&nbsp; '建立过滤器<br/>&nbsp;&nbsp;&nbsp; '选择过滤出图形中所有的标注对象<br/>&nbsp;&nbsp;&nbsp; Sset.Select 5, , , fType, fData<br/>&nbsp;&nbsp;&nbsp; Set ReturnAllSelectSet = Sset<br/>&nbsp; End With<br/>&nbsp; <br/>End Function</p><p></p>
页: [1]
查看完整版本: VB+类模块CLS+SelectionSets的应用