pxt2001
发表于 2019-9-15 06:41:07
这个程序很有用,配合"秋枫批量打印"。
pxt2001
发表于 2019-9-15 06:46:10
pxt2001 发表于 2019-9-15 06:41
这个程序很有用,配合"秋枫批量打印"。
秋枫批量打印程序虽然可以记忆页面设置,但是第一次打印图纸缺页面设置,每次需要手动设置。这个程序设置了"打印机页面设置",然后(c:bplot)启动秋枫批量打印,是完美解决CAD打印图纸的方案。
有空放个视频演示一下。
my0314cn
发表于 2020-8-28 09:42:59
从这个帖子学到很多,感谢楼主
my0314cn
发表于 2020-8-30 09:31:54
简易的多文件批量打印 1.预先设置好页面设置ps1 2.按照ps1打印打开的几个dwg文件 问题是,程序只能打印当前的dwg文件,求网友查错。(defun ax:2dpoint (pt) (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 1)) (list (car pt) (cadr pt)) ) ) )(defun objs-lst (objs) (setq obj-lst nil) (vlax-for obj objs (setq obj-lst (cons obj obj-lst))) (reverse obj-lst) )(defun getblock_name-yf (str var) (princ str) (if (and (/= var nil) (/= var "")) (progn (princ "<") (princ var) (princ ">")) ) (princ ":") (if (setq in (entsel "")) (setq var (cdr (assoc 2 (entget (car in))))) (eval var) ) ) ;;;获取打印文件存储位置 (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 ) );;;边界函数AX:GETBOUNDINGBOX (ENT) (defun ax:getboundingbox2 (obj) (vla-getboundingbox obj 'll 'ur) (mapcar 'vlax-safearray->list (list ll ur)) )(defun dwj-plot (path doc layout plotcfg drawingframe-blkname) ;;;根据图框块名过滤出某个布局中的图框 (setq drawingframe_lst nil) (vlax-for block (vla-get-block layout) (if (and (= (vla-get-objectname block) "AcDbBlockReference") (= (vla-get-name block) drawingframe-blkname) ) (setq drawingframe_lst (cons block drawingframe_lst)) ) ) (setq llurs nil) (foreach obj drawingframe_lst (setq llur (ax:getboundingbox2 obj)) (setq ll (reverse (cdr (reverse (car llur))))) (setq ur (reverse (cdr (reverse (cadr llur))))) ;;; 获取属性变量 (setq var (vla-getattributes obj)) ;;; 属性变量转为属性表 (setq attr-lst (vlax-safearray->list (vlax-variant-value var))) ;;; 根据属性标签,寻找属性文字 (foreach attr attr-lst (setq tagstring (vla-get-tagstring attr)) (cond ((= tagstring "图号") (setq tuhao (vla-get-textstring attr)) ) ((= tagstring "图纸名称") (setq tuming (vla-get-textstring attr)) ) ((= tagstring "图纸名称1") (setq tuming1 (vla-get-textstring attr)) ) (t t) ) ) (setq filename (strcat tuhao "_" tuming tuming1)) (setq llur (list ll ur filename)) (setq llurs (cons llur llurs)) ) (setq llurs (sxzy llurs 10)) (foreach x llurs (setq ll (car x)) (setq ur (cadr x)) (setq filename (last x)) ;;;设置打印范围 (vla-setwindowtoplot plotcfg (ax:2dpoint ll) (ax:2dpoint ur) ) ;;;指定页面设置为当前 (vla-copyfrom layout plotcfg) ;;;获取当前页面设置 (setq plot (vla-get-plot doc)) ;;;打印 (vla-plottofile plot (strcat path "\\" filename) ) ) ) (defun c:mp () (vl-load-com) (load "_lib-yf.lsp") (princ "\nmp-批量打印-多文件,预设页面设置,打开的文件都将被打印" ) (setq old (getvar "OSMODE")) (setvar "OSMODE" 0) ;;;cad (setq app (vlax-get-acad-object)) ;;;文档 (setq docs (vla-get-documents app)) ;;;当前文档 (setq *doc* (vla-get-activedocument app)) ;;;当前布局 ;;;(setq *lay* (vla-get-activelayout *doc*)) ;;;页面设置 (setq *plotcfgs* (vla-get-plotconfigurations *doc*)) (setq tmp2 (nth 2 (objs-lst *plotcfgs*))) ;;;页面设置名表 (setq pagesetup_name-lst nil) (vlax-for *plotcfg* *plotcfgs* (setq pagesetup_name (vla-get-name *plotcfg*)) (setq modeltype (vla-get-modeltype *plotcfg*)) (setq pagesetup_name-lst (cons pagesetup_name pagesetup_name-lst)) ) (setq pagesetup_name-lst (reverse pagesetup_name-lst)) (setq index 1) (setq tmp nil) (foreach x pagesetup_name-lst (setq tmp (cons (itoa index) tmp)) (setq tmp (cons "->" tmp)) (setq tmp (cons x tmp)) (setq tmp (cons ";" tmp)) (setq index (+ 1 index)) ) (setq tmp (reverse tmp)) (setq string (apply 'strcat tmp)) (setq string (strcat "\n选择页面设置名称<" string ">")) (setq index2 (getint-yf string index2)) ;;;页面设置名称 (setq pagesetup_name (nth (- index2 1) pagesetup_name-lst)) ;;;页面设置,用户要用的 (setq *plotcfg* (vla-item *plotcfgs* pagesetup_name)) (setq *windowtitle* (vla-get-windowtitle *doc*)) (vlax-for doc docs ;;;;;;当前文档的页面设置复制到其他文档 (if (/= (strcase (vla-get-windowtitle doc)) (strcase *windowtitle*) ) (progn ;;; 在其他文档创建页面设置名为pagesetup_name的页面设置 (setq plotcfg (vla-add (vla-get-plotconfigurations doc) pagesetup_name :vlax-false ) ) ;;;将*plotcfg*复制进plotcfg (vla-copyfrom plotcfg *plotcfg*) (vlax-for layout (vla-get-layouts doc) (if (/= (vla-get-name layout) "Model") (vla-copyfrom layout plotcfg ) ) ) ) ) ) (setq drawingframe-blkname (getblock_name-yf "\n选择图框,获取图框块名" drawingframe-blkname ) ) (princ drawingframe-blkname) (setq path (qf_getfolder "选择打印文件保存位置")) (vlax-for doc docs (setq doc doc) (setq plotcfgs (vla-get-plotconfigurations doc)) (setq plotcfg (vla-item plotcfgs pagesetup_name)) ;;; (vla-put-activedocument app doc) ;;; (vla-activate doc) (vlax-for layout (vla-get-layouts doc) (setq name (vla-get-name layout)) (if (/= name "Model") (dwj-plot path doc layout plotcfg drawingframe-blkname) ) ) );;;(setq docs (vla-get-documents (vlax-get-acad-object))) ;;;(setq doc (vla-item docs 0)) ;;;(setq plotcfgs (vla-get-plotconfigurations doc)) ;;;(setq plotcfg (vla-item plotcfgs "yf-dwg to pdf-A2")) ;;;(setq layout (vla-get-activelayout doc)) ;;;(dwj-plot path doc layout plotcfg drawingframe-blkname) (princ) )
技术工作室
发表于 2022-9-22 13:59:52
很有想法,值得学习。
zhangcn
发表于 2023-12-28 19:10:47
本帖最后由 zhangcn 于 2024-1-11 13:23 编辑
感谢楼主分享优秀源码,本人结合chatGPT优化,能实现一键设置A4、A3打印,一键发布A4、A3到打印机打印,一键导JPG、PDF到桌面。兼容“模型”环境“布局”环境随便打。
详见此贴
http://bbs.mjtd.com/thread-189219-1-1.html?_dsign=607bb88b
寒潮大冬瓜
发表于 2024-5-15 20:45:08
my0314cn 发表于 2020-8-30 09:31
简易的多文件批量打印 1.预先设置好页面设置ps1 2.按照ps1打印打开的几个dwg文件 问题是,程序只能打印当 ...
似乎多一个右括号
寒潮大冬瓜
发表于 2024-5-15 20:47:53
这个保存为lsp的文件,提示多一个右括号,我删掉了