嘻皮客娱乐学习网

标题: Private Sub Test()用VBA在cad中查找包含某字符串的文本,并显示该文本的内容和插... [打印本页]

作者: xipick    时间: 2014-8-26 14:13
标题: Private Sub Test()用VBA在cad中查找包含某字符串的文本,并显示该文本的内容和插...
例子:在cad文件中查找包含“基础设计说明”的文本,并取得该文本所有字符串和其插入点的坐标。

Private Sub Test()

    Dim objEnt As AcadEntity
    Dim nCount As Long
    Dim i As Long
    Dim x, y As Double
    Dim a As Variant
    Dim strFind  As String
   
    strFind = "没有共" '查找内容---
     
    nCount = ThisDrawing.ModelSpace.Count
    For i = 1 To nCount
        Set objEnt = ThisDrawing.ModelSpace.Item(i - 1)
            
            If objEnt.ObjectName = "AcDbMText" Or objEnt.ObjectName = "AcDbText" Then
               
                If InStr(objEnt.TextString, strFind) > 0 Then
               
                MsgBox objEnt.TextString
               
               a = objEnt.InsertionPoint
               
                x = a(0): y = a(1)
               
                MsgBox "该文字插入点坐标为:" & vbCr & "x:" & x & vbCr & "y:" & y
               
                End If
               
           End If
    Next
   
End Sub




欢迎光临 嘻皮客娱乐学习网 (http://www.xipick.com/) Powered by Discuz! X3.3