Autolisp对CAD二次开发如何一次性处理一批dwg格式的工程图,求大神帮忙,急求! 100
2个回答
展开全部
;给你个示例代码,不开图批量设置文件夹下dwg字体并清理
(defun c:puall( / cadobj file ob path vercad i styob styname docobj styles styhz txtob)
(vl-load-com)
(alert "请确认您已对图纸备份!!!\n请确认待清理文件未被打开")
;取得目录
(defun qf_getFolder (msg / WinShell shFolder path catchit)
(vl-load-com)
(setq winshell (vlax-create-object "Shell.Application"))
(setq shFolder (vlax-invoke-method WinShell 'BrowseForFolder 0 msg 1))
(setq
catchit (vl-catch-all-apply
'(lambda () (setq shFolder (vlax-get-property shFolder 'self)) (setq path (vlax-get-property shFolder 'path))
)
)
)
(if (vl-catch-all-error-p catchit)
nil
path
)
)
;出错处理
(defun *error* (msg)
(if (= nil cadob)
(princ "\n您已取消操作!")
(progn
(Vlax-Invoke-Method cadobj 'Quit)
(princ "\n您已取消操作!")
)
)
(princ)
)
(setq file nil)
(setq path (strcat (qf_getFolder "请选取要清理的文件所在目录") "\\"))
(setq cadobj (vlax-create-object "AUTOCAD.Application"))
(setq n 0)
(foreach file (vl-directory-files path "*.dwg" 1)
(setq docobj (vla-open (vla-get-documents cadobj) (strcat path file)))
(setq styles (Vlax-Get-property docobj 'textstyles))
(setq styhz (vlax-invoke-method styles 'add "HZ"))
(vlax-put-property styhz 'bigfontfile "hztxt.shx")
(vlax-put-property styhz 'fontfile "simplexs.shx")
(vlax-put-property styhz 'width 0.7)
(Vlax-Put-Property docobj 'ActiveTextStyle styhz)
(vlax-for txtob (Vlax-Get docobj 'ModelSpace)
(cond
((= "AcDbText" (Vlax-Get txtob 'ObjectName ))
(vlax-put-property txtob 'stylename "HZ"))
((= "AcDbMText" (Vlax-Get txtob 'ObjectName ))
(vlax-put-property txtob 'stylename "HZ"))
)
)
(vla-purgeall docobj)
(prompt (strcat "\n" file " 已设置字体HZ,并清理完成"))
(Vlax-Invoke-Method docobj 'SaveAs (strcat path file))
(setq n (+ 1 n))
)
(Vlax-Invoke-Method cadobj 'Quit)
(alert (strcat "共清理" (itoa n) "张图纸\n请逐一检查"))
(princ)
)
(princ "\n调用命令:puall 用前请备份,用后请核对")
(princ)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询