文件后缀名要用lsp 就可以用了 (defun c:pp() (setq sv (ssget "I"' ((0 . "LINE")))) ;判断是否有已经有选择''''''''''''''''''''''''''' (if (= sv nil)(setq printtype (getstring "\nAuto-search batch-plot全部(模型+布局)[A]/部分[P]:<A>"))) (setq printt "unknow") (if (or (= printtype "") (= printtype "A") (= printtype "a")) (setq sv (ssget "X" (list (cons 0 "line")))) (setq sv (ssget ' ((0 . "LINE")))) ) ;_ 结束if ;取得打印纸张打印 (setq papersc (getstring "\n出图大小A3[3]/A4[4]:<A3>")) (setq scale "unknow") (if (or (= papersc "") (= papersc "3"))(setq scale "1")(setq scale "1:1.414")) ;_ 结束if (if (or (= papersc "") (= papersc "3"))(setq paper "A3")(setq paper "A4")) ;_ 结束if ;============================================================================== ;控制变量说明 ; printt 打印的类别 ; xspace x方向打印偏移 ; yspace y方向打印偏移 ; myprint 使用打印机名称 ; modetype 空间类别 ; ctb_type 使用的打印样式 ; drawing_tp 图形宽度(只能为420mm图形单位) ; keyline 搜索的线条长度(为字符型变量) ;-取得注册表中默认打印机-------------------------------------------------------- (defun defultprint (/ device) (substr (setq device (vl-registry-read "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows" "Device") ) 1 (vl-string-search "," device) ) ) ;============================================================================== (command ".ucs" "W") (command "setvar" "dimzin" "0") (command "setvar" "DYNMODE" "0") (setq xspace -4.26) (setq yspace -2) (setq myprint (defultprint)) (setq modetype (getvar "tilemode")) (setq CADVER (getvar "ACADVER")) ;得到cad的版本号 (setq drawing_tp 420) (setq xyspace (list xspace yspace)) (setq ctb_type "monochrome.ctb") (setq keyline "420.0") (setq keyang1 "0.0000") (setq keyang2 "6.2832") (setq boundx1 (car p_1)) (setq boundy1 (cadr p_1)) (setq boundx2 (car p_2)) (setq boundy2 (cadr p_2)) (if (> boundx1 boundx2) (setq boundtemp boundx1 boundx1 boundx2 boundx2 boundtemp ) ;_ 结束setq ) ;_ 结束if (if (> boundy1 boundy2) (setq boundtemp boundy1 boundy1 boundy2 boundy2 boundtemp ) ;_ 结束setq ) ;_ 结束if ;======至此完成输入数据处理======= ;(setq sv (ssget "X" (list (cons 0 "line")))) (setq ls (sslength sv)) (setq prpage 0) (setq s 0) (repeat ls (setq vv (ssname sv s)) ;得到sp,ep,mp的坐标------------------------------------- (setq sp (cdr (assoc 10 (entget vv)))) (setq sp_x (car sp)) (setq sp_y (cadr sp)) ;+++++++++++++++++++++++++++ (setq ep (cdr (assoc 11 (entget vv)))) (setq ep_x (car ep)) (setq ep_y (cadr ep)) ;+++++++++++++++++++++++++++ (setq mp△x (/ (- ep_x sp_x) 2)) (setq mp△y (/ (- ep_y sp_y) 2)) ;得到过程结束---------------------------------------------- (setq s_epdis (distance sp ep)) (setq Len (rtos s_epdis 2 1)) ;----- (setq s_epang (angle sp ep)) (setq ang (rtos s_epang 2 4)) ;------ ;(setq boundkey "off") ;(if (and (and (> sp_x boundx1) (< sp_x boundx2)) (and (and (> sp_y boundy1) (< sp_y boundy2)))) (setq boundkey "on")) (if (and (= Len keyline) (or (= ang keyang1) (= ang keyang2))) (progn (setq s_prp1 sp) (setq prpage (+ prpage 1)) (setq prscreemtext1 "\n正在打印第\t") (setq prscreemtext2 "\t张图纸:马占祥提供") (setq prscreemtext (strcat (strcat prscreemtext1 (itoa prpage)) prscreemtext2) ;_ 结束strcat ) ;_ 结束setq (princ prscreemtext) (command "modemacro" prscreemtext "") (setq s_prp2 (list (+ (car s_prp1) drawing_tp)(+ (cadr s_prp1) 296)) ;_ 结束list ) ;_ 结束setq (if (= 1 modetype) (command ".plot" "y" "" myprint paper "M" "L" "" "w" s_prp1 s_prp2 scale "C" "Y" ctb_type "Y" "N" "N" "N" "Y") ;_ 结束command (command ".plot" "y" "" myprint paper "M" "L" "" "W" s_prp1 s_prp2 scale "C" "Y" ctb_type "Y" "Y" "Y" "N" "N" "N" "Y") ;_ 结束command ) ;_ 结束if ) ;_ 结束progn ) ;_ 结束if (setq s (+ s 1)) ) ;_ 结束repeat (command "modemacro" " " "") (princ "\n版权所有:马占祥") (princ) ) ;_ 结束defun ;mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm下面的为修改直线方向的lisp代码,帮助修改图框下线是否为420cm、0° (defun C:FX(/ tmp ed ent m n endpt1 endpt2 newline name) (princ "\n交换直线、多段线或标注的起点和终点.请选择直线、多段线或标注:\n") ;选择直线或标注,注意逻辑组的使用 (setq tmp (ssget (list (cons -4 "<OR")(cons 0 "LINE") (cons 0 "LWPOLYLINE") (cons 0 "DIMENSION") (cons -4 "or>")))) (if tmp (progn (setq n (sslength tmp) m 0) (repeat n (setq ent (ssname tmp m)) (setq ed (entget ent)) ;(ts "\nent=") ;(ts ent) (setq name (cdr (assoc 0 ed))) (if (= name "LWPOLYLINE") (lwpolyline_reverse ent ed) (progn (setq endpt1 (cons 11 (cdr (assoc 10 ed) ))) (setq endpt2 (cons 10 (cdr (assoc 11 ed) ))) (setq ed (subst endpt1 (assoc 11 ed) ed)) (setq ed (subst endpt2 (assoc 10 ed) ed)) (setq newline ed) ;删除原对象并生成相同句柄的新对象,注意: ;enddel 对象名称ent不是对象数据表ed ;endmod entmake 的不是对象名称ent是对象数据表ed (entdel ent) (entmake newline) ) );end if (setq m (1+ m)) );end repeat ) );end if tmp (princ "\n共处理了") (if m (princ m) (princ "0")) (princ "条直线(多段线、标注)。") (princ) );end ;--------------------------------------------------------------------------- ;多段线的换向程序, (DEFUN lwpolyline_reverse (lwpent data / num data one points tempnum tempent) (SETQ points nil) (FOREACH one data (PROGN (IF (= (CAR one) 10) (SETQ points (APPEND points (LIST one))) ) ) ) (SETQ points (REVERSE points)) (SETQ tempnum 0) (SETQ tempent nil) (FOREACH one data (PROGN (IF (= (CAR one) 10) (SETQ tempent (APPEND tempent (LIST (NTH tempnum points))) tempnum (1+ tempnum) ) (SETQ tempent (APPEND tempent (LIST one))) ) ) ) (entdel lwpent) (entmake tempent) (PRINC) );end lwpolyline_reverse ;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww |