|
- ;;
- (defun pdfdhk (/ lst mr1 mr2 dcl_id layout name nameli styleli style );对话框
-
- (setq dcl_id (dcl-write
- '("dayinxx:dialog{label="PDF 打印";"
- "spacer;"
- ":row{"
- ":column{label="图 幅 :";"
- ":radio_button {
- label = "A1" ;
- key = "d_A1" ;
- width = 10 ;
- }"
- ":radio_button {
- label = "A2" ;
- key = "d_A2" ;
- width = 10 ;
- }"
- ":radio_button {
- label = "A3" ;
- key = "d_A3" ;
- }"
- ":radio_button {
- label = "A4" ;
- key = "d_A4" ;
- }"
- "}"
- ":column{"
- ":button{label="黑白";key="heibai";height=2.5;is_default=true;}"
- ":button{label="彩色";key="caise";height=2.5;is_enabled=true;}"
- ":button{label="退出";key="cancel";height =2.5;is_cancel=true;}"
- "}"
- ":column{label="---导出图片选项---";"
- ":toggle {
- label = "【导出图片】" ;
- key = "tp" ;
- width = 10 ;
- }"
- ":edit_box{label="图片dpi";key="dpi";edit_width=8;value=300;}"
- ":edit_box{label="图片名";key="tpm";edit_width=8;}"
- ":edit_box{label="导出页";key="ys";edit_width=8;}"
- "}"
- "}"
- "}"
- )
- )
- )
- (new_dialog "dayinxx" dcl_id)
- (mode_tile "d_A3" 2);单选框设置默认值
- (set_tile "ys" "0-100");设置页数的默认值
- (set_tile "tpm" "xxx");设置图片名的默认值
- (action_tile "d_A1" "(setq tufu 1)");单选框为A1时 设置 tufu 为 2
- (action_tile "d_A2" "(setq tufu 2)");单选框为A2时 设置 tufu 为 2
- (action_tile "d_A3" "(setq tufu 3)");单选框为A3时 设置 tufu 为 3
- (action_tile "d_A4" "(setq tufu 4)");单选框为A4时 设置 tufu 为 4
- (action_tile "tp" "(get-xsys)");
- (action_tile "heibai" "(getxx 1)(done_dialog)");按确认键时运行 get 函数取得 打印份数的值。
- (action_tile "caise" "(getxx 2)(done_dialog)")
- (action_tile "cancel" "(exit)");按退出键时运行 exit,也可运行其它函数。
- ;;action_tile 可以为某一控件指定一个动作,这个动作可以是命令也可以是一个函数
- (start_dialog);启动对话框
- (unload_dialog dcl_id);卸载DCL文件
- (if (= tufu nil)(setq tufu 3))
- )
- (defun getxx (yanse /)
- (if (= yanse 1)(setq dyys "monochrome.ctb")(setq dyys "acad.ctb"))
- )
- ;像素、页数
- (defun get-xsys (/ cs f)
- (setq tupian 1)
- (setq dpi (fix(atof (get_tile "dpi"))));dpi 值
- (setq ys (get_tile "ys"));页数范围
- (setq tpm (get_tile "tpm"))
- (setq f (open "D:\\gyw\\tupian.txt" "w"))
- (setq cs (list dpi dpi ys ys));输出的是以表的形式
- (princ cs f)
- (close f)
- )
- ;临时生成Dcl文件,返回dcl_id ;by nonsmall
- (defun Dcl-Write (lst / dcl_file file str dcl_id dcl-name)
- (vl-load-com)
- (setq dcl_file (vl-filename-mktemp nil nil ".dcl"))
- (setq file (open dcl_file "w"))
- (foreach str lst (write-line str file))
- (close file)
- (setq dcl_id (load_dialog dcl_file)) ;对话框加载
- (vl-file-delete dcl_file) ;加载后删除dcl文件
- dcl_id
- )
- ;批量打印 A3 A2 PDF 到桌面\xxxx
- (defun c:tt (/ cs dxf dyys en end f fuzz i int k L ls maxp minp mz p1 p2 se st tkm tkmz tufu tz wenjian wj x y yanse zm newse dxlst dxj se dxf int fuzz k tpm tupian )
- (setvar "CMDECHO" 0)
- (setvar "DYNMODE" 1);打开动态输入
- (pdfdhk);对话框
- (if (= tufu 1)(setq tufu "ISO expand A1 (841.00 x 594.00 毫米)"))
- (if (= tufu 2)(setq tufu "ISO expand A2 (594.00 x 420.00 毫米)"))
- (if (= tufu 3)(setq tufu "ISO expand A3 (420.00 x 297.00 毫米)"))
- (if (= tufu 4)(setq tufu "ISO expand A4 (297.00 x 210.00 毫米)"))
- (setq zm (vlax-invoke-method
- (vlax-get-property (vlax-create-object "wscript.shell") 'SpecialFolders)
- 'Item
- "desktop"
- )
- );获取默认桌面
- (vl-mkdir (setq wj (strcat zm "\" "xxxx")));在桌面建立临时文件夹xxxx
- (setq ls (strcat wj "\" "xxx.txt"));建立一个临时文件,合并.bat要用
- (setq en (ssget (list(cons 2 "hzA3h,A3s,A3h,hzA3s,hztk*,DSDSAD,hzjxk"))))
- (if (= en nil)(exit))
- (setq i 0)
- (setq L 0);记录打印的次数
- (sort-se en 10 0 3.0 nil);从左到右
- (sort-se newse 10 1 3.0 t);从上到下
- (repeat (sslength newse)
- (setq L (1+ i));记录打印的次数
- (setq mz (rtos L));导出PDF的文件名。
- (setq end (ssname newse i))
- (vla-getboundingbox(vlax-ename->vla-object end) 'minp 'maxp)
- (setq p1 (vlax-safearray->list minp)
- p2 (vlax-safearray->list maxp)
- ) ;获得包围框,左上角点 P1,右下角点P2
- (setq x (abs (- (car p2) (car p1))))
- (setq y (abs (- (cadr p2) (cadr p1))))
- (if (> y x) (setq st "p") (setq st "l"));判断横向还是纵向,p纵向,l横向
- (setq wenjian (strcat wj "\" mz))
- (dayin p1 p2 tufu wenjian)
- ;(setq L (1+ L));记录打印的次数
- (setq i (1+ i))
- )
- (if(= i 0);打印次数为 0
- (progn
- (getreal (strcat "共导出 "(rtos L 2 0)" 张图纸"))
- (exit)
- )
- );没有选到有效图框
- (if(= tpm nil)(setq tpm "xxx"))
- (setq f (open ls "w"));xxxx\xxx.txt 记录导出数量
- (setq cs (list L tpm));输出的是以表的形式
- (princ cs f)
- (close f)
- (command ".shell" "合并.bat|exit");运行批处理文件
- (command ".delay" 1000)
- (if(= tupian 1)(command ".shell" "导出图片.bat|exit"));运行批处理文件
- (command "start" wj);打开导出的PDF文件夹
- (getreal (strcat "共导出 "(rtos L 2 0)" 张图纸"));提示导出几张图
- (princ)
- )
- (defun dayin ( p1 p2 tufu wenjian / dayinji )
- (setq dayinji "dwg to pdf.pc3")
- (command-s "-plot" "y" ; 是否需要详细打印配置
- "模型" ; 输入布局、模型名称
- dayinji ; 输入输出设备的名称 此处例举虚拟打印机 pdfFactory Pro
- ; (lisp语言中的一个 \ 符号需要用 \\符号表示,即\=>\\)
- ; 例如:共享打印机 \\Adminstractor\Kyocera KM-2560 KX应该表示为\\\\Adminstractor\\Kyocera KM-2560 KX
- tufu ; 输入图纸尺寸A4
- "m" ; 输入图纸单位(I:英寸 M:毫米)
- st ; 输入图形方向(纵向:P 横向:L)
- "n" ; 是否反向打印
- "w" ; 输入打印区域(显示:D范围:E图形界限:L 视图:V 窗口:W)
- p1 ; 打印图框左下角点坐标
- p2 ; 打印图框右上角点坐标
- "f" ; 输入打印比例(F:布满)
- "c" ; 输入打印偏移(居中打印:C)
- "y" ; 是否按样式打印
- dyys ; 输入打印样式名称
- "y" ; 是否打印线宽
- "a" ; 输入着色打印设置(按显示:A 线框:W 消隐:H 渲染:R)
- wenjian ; 是否打印到文件,pdf或图片时的要用到的,由路径+文件名组成
- "y" ; 是否保存对页面设置的修改
- "Y" ; 是否继续打印
- )
- )
- ;=================================================================
- ;;; 通用函数 选择集按照给定的组码值进行排序
- ;;;输出 新对象集 newse
- ;参数说明:se ----要排序的选择集
- ;dxf ----排序依据的组码号
- ;int ----如果组码值为一个表,则int指出使用第几个;否则nil
- ; fuzz----允许偏差;若无为nil
- ; k ----t表示从大到小,nil表示从小到大
- ;返回值:排序后的选择集
- ;示例:;
- ;(sort-se ss 10 0 5.0 t ) 表示按照10组码的x坐标值进行排序,允许偏差值为5.0,顺序为从大到小
- ;(sort-se ss 10 1 3.0 nil) 表示按照10组码的y坐标值进行排序,允许偏差值为3.0,顺序为从小到大
- ;(sort-se ss 8 nil nil nil) 表示按照8组码值(图层名称)进行排序,顺序为从小到大
- ;以下是组合应用
- ;(sort-se en 10 0 3.0 nil);从左到右
- ;(sort-se se 10 1 3.0 t);从上到下
- (defun sort-se (se dxf int fuzz k / ent index lst newlst tmp)
- (setq lst '()
- index 0
- )
- (repeat (sslength se)
- (setq ent (entget (ssname se index))
- tmp (cdr (assoc dxf ent))
- )
- (if (and
- int
- (= (type int) 'int)
- (= (type tmp) 'list)
- (< int (length tmp))
- )
- (setq tmp (nth int tmp))
- )
- (setq lst (cons (list tmp (cdr (assoc 5 ent))) lst))
- (setq index (1+ index))
- )
- (if (and
- fuzz
- (or
- (= (type fuzz) 'int)
- (= (type fuzz) 'real)
- )
- (or
- (= (type tmp) 'int)
- (= (type tmp) 'real)
- )
- )
- (setq newlst (vl-sort lst (function (lambda (e1 e2) (< (+ (car e1) fuzz) (car e2))))))
- (setq newlst (vl-sort lst (function (lambda (e1 e2) (< (car e1) (car e2))))))
- )
- (if k
- (setq newlst (reverse newlst))
- )
- (setq newse (ssadd))
- (foreach tmp newlst
- (setq newse (ssadd (handent (cadr tmp)) newse))
- )
- newse
- )
复制代码 |
|