本帖最后由 kucha007 于 2023-6-10 07:09 编辑
最早是根据文字样式名称修改,见此贴:http://bbs.mjtd.com/thread-186303-1-1.html
现在是获取文字样式的字体名称,如果不是黑体宋体或形字体(ltypeshp.shx),就规整为设置的标准字体。
- ;如果不成功则抓取错误,如果成功就执行程序
- (defun K:CatchApply (fun args / result)
- (if
- (not
- (vl-catch-all-error-p
- (setq result (vl-catch-all-apply
- (if (= 'SYM (type fun)) fun (function fun))
- args
- )
- )
- )
- )
- result
- )
- )
函数部分:
- ;(字体)非黑宋规整为标准字体
- (defun K:StyleNonBoldSong (FNam BFNam Width / TmpDoc obj FindFlag TypeFace Bold Italic Charset PitchandFamily)
- (setq TmpDoc (vla-get-activedocument (vlax-get-acad-object)))
- (vlax-for obj (vla-get-textstyles TmpDoc)
- (if
- (and
- (not (vl-string-search "|" (vla-get-Name obj)))
- (not (vl-string-search "$" (vla-get-Name obj)))
- );排除外部参照的字体样式
- (progn
- (setq FindFlag Nil)
- (K:CatchApply 'vla-Getfont (list obj 'TypeFace 'Bold 'Italic 'Charset 'PitchandFamily))
- (if (eq TypeFace "")
- (if (/= (vla-get-fontfile obj) "ltypeshp.shx");线型形文件
- (setq FindFlag T)
- )
- (if (not (wcmatch (strcase TypeFace) "**宋**,**FANGSONG**,**黑体**,**SIMHEI**"))
- (setq FindFlag T)
- )
- )
- (if FindFlag
- (progn
- (K:CatchApply 'vla-setfont (list obj FNam "false" "false" 1 0));TTF
- (K:CatchApply 'vla-put-fontfile (list obj FNam));SHX
- (K:CatchApply 'vla-put-bigfontfile (list obj BFNam));大字体
- (K:CatchApply 'vla-put-width (list obj Width));宽度因子
- )
- )
- )
- )
- )
- (princ)
- )
用法:
- (K:StyleNonBoldSong "仿宋_GB2312" nil 0.8);TTF
- (K:StyleNonBoldSong "txt" nil 0.8);SHX:不使用大字体
- (K:StyleNonBoldSong "gbenor" "gbcbig" 0.8);SHX:使用大字体
其它:
;获取TTF字体名称
- (vla-Getfont obj 'TypeFace 'Bold 'Italic 'Charset 'PitchandFamily)
- (princ TypeFace)
复制代码
;打印所有字体样式名称- (defun C:TT ()
- (vlax-for TS (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
- (princ (strcat "\n" (vla-get-Name TS)))
- )(princ)
- )
;打印非外部参照的字体样式名称- (defun C:TT ()
- (vlax-for TS (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
- (if (not (vl-string-search "|" (vla-get-Name TS)))
- (princ (strcat "\n" (vla-get-Name TS)))
- )
- )(princ)
- )
;打印非外部参照的字体样式所使用的字体名称
- (vlax-for TS (vla-get-textstyles (vla-get-activedocument (vlax-get-acad-object)))
- (if (not (vl-string-search "|" (vla-get-Name TS)));排除外部参照
- (progn
- (setq FontNam (vla-get-fontfile (vlax-ename->vla-object (tblobjname "style" (vla-get-Name TS)))))
- (princ (strcat "\n" FontNam))
- )
- )
- )(princ)
|