ningyong58 发表于 2009-2-11 13:21:00

如何统一MTEXT的文字格式

<p>在CAD中,有很多MTEXT的shx不一样,有txt.shx,有HZTXT.SHX,KHZTEX.SHX</p><p>如何将他们统一为hztx.shx</p>

dianbotang 发表于 2009-3-26 02:22:00

本帖最后由 作者 于 2009-3-26 2:23:19 编辑 <br /><br /> <p>先建立字体为hztx.shx的文字样式,并应用到所有多行文字。</p><p>特性栏-文字-内容,如果多行文字带有复杂格式,可应用以下vba程序,基本可以解决问题:</p><p>Option Explicit</p><p>' 拾取多行文字,获得其文字内容,并进行替换<br/>Public Sub GetAndReplaceMTextString()<br/>&nbsp; Dim SSet As AcadSelectionSet<br/>&nbsp; Set SSet = ThisDrawing.PickfirstSelectionSet<br/>&nbsp; If SSet.Count = 0 Then<br/>&nbsp;&nbsp;&nbsp; MsgBox "未选择对象"<br/>&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp; End If<br/>&nbsp; Dim objMText As AcadEntity<br/>&nbsp; Dim ptMin As Variant, ptMax As Variant<br/>&nbsp; Dim ptCenter(0 To 2) As Double<br/>&nbsp; Dim radius As Double<br/>&nbsp; For Each objMText In SSet<br/>&nbsp;&nbsp;&nbsp; If TypeOf objMText Is AcadMText Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objMText.TextString = GetMTextUnformatString(objMText.TextString)<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp; Next<br/>&nbsp; ThisDrawing.Regen True<br/>End Sub</p><p>Public Function GetMTextUnformatString(MTextString As String) As String<br/>&nbsp;&nbsp;&nbsp; Dim s As String<br/>&nbsp;&nbsp;&nbsp; Dim RE As Object<br/>&nbsp;&nbsp;&nbsp; ' 获取Regular Expressions组件<br/>&nbsp;&nbsp;&nbsp; Set RE = ThisDrawing.Application.GetInterfaceObject("Vbscript.RegExp")<br/>&nbsp;&nbsp;&nbsp; ' 忽略大小写<br/>&nbsp;&nbsp;&nbsp; RE.IgnoreCase = True<br/>&nbsp;&nbsp;&nbsp; ' 搜索整个字符串<br/>&nbsp;&nbsp;&nbsp; RE.Global = True<br/>&nbsp;&nbsp;&nbsp; s = MTextString<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '替换\\字符<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "<a>\\\\</a>"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, Chr(1))<br/>&nbsp;&nbsp;&nbsp; '替换\{字符<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "\\{"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, Chr(2))<br/>&nbsp;&nbsp;&nbsp; '替换\}字符<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "\\}"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, Chr(3))<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '删除段落缩进格式<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "<a href="file://pi/">\\pi</a>(.[^;]*);"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "")<br/>&nbsp;&nbsp;&nbsp; '删除制表符格式<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "<a href="file://pt/">\\pt</a>(.[^;]*);"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "")<br/>'&nbsp;&nbsp;&nbsp; '删除堆迭格式<br/>'&nbsp;&nbsp;&nbsp; RE.Pattern = "<a href="file://S(.[^;]*)(/^|#|//">\\S(.[^;]*)(\^|#|\\</a>)(.[^;]*);"<br/>'&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "$1$3")<br/>&nbsp;&nbsp;&nbsp; '删除字体、颜色、字高、字距、倾斜、字宽、对齐格式<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "(<a href="file:///F|//C|//H|//T|//Q|//W|//A">\\F|\\C|\\H|\\T|\\Q|\\W|\\A</a>)(.[^;]*);"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "")<br/>&nbsp;&nbsp;&nbsp; '删除下划线、删除线格式<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "(<a href="file:///L|//O|//l|//o">\\L|\\O|\\l|\\o</a>)"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "")<br/>&nbsp;&nbsp;&nbsp; '删除不间断空格格式<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "\\~"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, " ")<br/>&nbsp;&nbsp;&nbsp; '删除换行符格式<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "<a href="file://P/">\\P</a>"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "")<br/>&nbsp;&nbsp;&nbsp; '删除换行符格式(针对Shift+Enter格式)<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = vbLf<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "")<br/>&nbsp;&nbsp;&nbsp; '删除{}<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "({|})"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '替换回<a href="file://,/{,/">\\,\{,\</a>}字符<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "\x01"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "\")<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "\x02"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "{")<br/>&nbsp;&nbsp;&nbsp; RE.Pattern = "\x03"<br/>&nbsp;&nbsp;&nbsp; s = RE.Replace(s, "}")<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set RE = Nothing<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; GetMTextUnformatString = s<br/>End Function</p><p></p>
页: [1]
查看完整版本: 如何统一MTEXT的文字格式