分享

AutoCAD VBA提取多行文字内容

 Excel实用知识 2021-11-21
Public Function GetMTextUnformatString(MTextString As String) As String
Dim s As String
Dim RE As Object
Set RE = ThisDrawing.Application.GetInterfaceObject('VBscript.RegExp')
RE.IgnoreCase = True
RE.Globa = True
s = MTextString
RE.pattern = '\\\'
s = RE.Replace(s, Chr(1))
RE.pattern = '\\{'
s = RE.Replace(s, Chr(2))
RE.pattern = '\\}'
s = RE.Replace(s, Chr(3))
RE.pattern = '\\pi(.[^;]*);'
s = RE.Replace(s, '')
RE.pattern = '\\pt(.[^;]*);'
s = RE.Replace(s, '')
RE.pattern = '\\s(.[^;]*)(\^|#|\\)(.[^;]*);'
s = RE.Replace(s, '$1$3')
RE.pattern = '(\\F|\\C|\\H|\\T|\\Q|\\W|\\A)(.[^;];'
s = RE.Replace(s, '')
RE.pattern = '\\~'
s = RE.Replace(s, '')
RE.pattern = '\\P'
s = RE.Replace(s, '')
RE.pattern = vbLf
s = RE.Replace(s, '')
RE.pattern = '({|})'
s = RE.Replace(s, '')
RE.pattern = '\x01'
s = RE.Replace(s, '\')
RE.pattern = '\x02'
s = RE.Replace(s, '{')
RE.pattern = '\x03'
s = RE.Replace(s, '}')
Set RE = Nothing
GetMTextUnformatString = s
End Function
Public Sub GetMTextString()
Dim objMText As AcadMText
Dim ptPick As Variant
ThisDrawing.Utility.GetEntity objMText, ptPick
MsgBox GetMTextUnformatString(objMText.TextString)
End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约