
| 出版日期:1999-09-06 总期号:855 本年期号:65 |
|
利用autolisp 和dcl实现动态插入
马伟国 笔者所在单位采用autocad作为绘图平台进行工程设计和开发,在工程绘图过程中,经常会用到明细表的生成,如果明细表很多则需要一条一条地画出,这样将大大降低绘图效率,为了能实现一次可将明细表画出并准确插入到标题栏上,笔者在工作中尝试用autolisp语言和dcl对话框实现上了上述功能,从而大大提高了绘图效率。命令运行时,系统将出现提示对话框。 用户只要输入明细表的起、止序号和比例,确认后即可将所需的标准明细表自动画出,并插入到标题栏的准确位置。 画明细表的lisp程序如下: ;画明细表外边框及各横线: (defun drawl() (setvar ″cmdecho″ 0) (setvar ″osmode″ 0) (command ″layer″ ″m″ ″lll″ ″c″ red ″ ″) (setq inp (getpoint″\n 请输入明细表插入点(右下角):″)) (setq num1 (atoi aa)) (setq num2 (atoi bb)) (while (> num1 num2) (alert ″输入错误(结束序号必须大于起始序号),\n要重新输入起始序号和结束序号,\n请按回车键重新调用对话框。″) (exit)) (setq num (+ 1 (- num2 num1))) (setq x (atof ab)) (if (not *x) (setq *x 1)) (setq ptx2(car inp)) (setq ptx1(- (car inp) 180.0 )) (setq n 0) (setq p1(polar inp pi 180)) (setq p2(polar p1 (/ pi 2) (+ 10.0 (* 8 num)))) (setq p3(polar p2 0 180)) (setq pty0(+ 10.0 (cadr inp))) (setq p4(list ptx1 pty0)) (setq p5(list ptx2 pty0)) (setq scal(/ (getvar ″dimtxt″) 5)) (command ″pline″ inp ″w″ (* 0.7 scal) (* 0.7 scal) p1 p2 p3 ″c″ ″ ″line″ p4 p5 ″) (while (> num n) (setq n (+ 1 n)) (setq py(* 8 n)) (setq pty(+ py pty0)) (setq pt1(list ptx1 pty)) (setq pt2(list ptx2 pty)) (command ″line″ pt1 pt2 ″))) ;画明细表内竖线: (defun con() (setq ptx1(+ 8.0 (- (car inp) 180))) (setq ptx2(+ 50.0 (- (car inp) 180))) (setq ptx3(+ 90.0 (- (car inp) 180))) (setq ptx4(+ 98.0 (- (car inp) 180))) (setq ptx5(+ 140.0 (- (car inp) 180))) (setq ptx6(+ 160.0 (- (car inp) 180))) (setq ptx7(+ 150.0 (- (car inp) 180))) (setq pty1(cadr inp)) (setq pty2(+ pty0 (* 8 num))) (setq ptl1(list ptx1 pty1)) (setq ptl2(list ptx1 pty2)) (setq ptl3(list ptx2 pty1)) (setq ptl4(list ptx2 pty2)) (setq ptl5(list ptx3 pty1)) (setq ptl6(list ptx3 pty2)) (setq ptl7(list ptx4 pty1)) (setq ptl8(list ptx4 pty2)) (setq ptl9(list ptx5 pty1)) (setq ptl10(list ptx5 pty2)) (setq ptl11(list ptx6 pty1)) (setq ptl12(list ptx6 pty2)) (setq ptl13(list ptx7 pty0)) (setq ptl14(list ptx7 pty2)) (command ″line″ ptl1 ptl2 ″" ″line″ ptl3 ptl4 ″" ″line″ ptl5 ptl6 ″" ″line″ ptl7 ptl8 ″" ″line″ ptl9 ptl10 ″" ″line″ ptl11 ptl12 ″" ″line″ ptl13 ptl14 ″" ) ) ;添加明细表表头及书写序号: (defun te()v (getvar ″textsize″) (setq word num2) (setq nu num1) (setq pty01(+ 2.0 pty0)) (command ″insert″ ″/autocad r14/kaifa/mxb/btlt″ inp 1 1 ″0″) ;明细表表头利用插块方式插入。 (repeat num (setq ptt(list (- ptx1 4) (+ pty01 (* 8 (- num2 nu))))) (command ″text″ ″j″ ″c″ ptt 3.5 ″word″) (setq word(1- word)) (setq nu(1+ nu))) (setq t(ssget ″x″ ′((8 . ″lll″)))) (if (not x) (setq x *x) (setq *x x)) (command ″scale″ t ″ inp x″)) ;用于取得由对话框输入的关键值 (defun ma() (setq aa (get_tile ″n1″)) (setq bb (get_tile ″n2″)) (setq ab (get_tile ″qa″)) (done_dialog)) ;主程序 (defun c:mxb() (setq dcl_id (load_dialog ″mxb.dcl″)) (if (not(new_dialog ″xb″ dcl_id)) (exit)) (action_tile ″accept″ ″(ma)″) (action_tile ″cancel″ ″(done_dialog)″) (start_dialog) (drawl) (con) (te) (redraw) (setvar ″osmode″ 32) (command ″layer″ ″s″ ″thick-solid″ ″) (unload_dialog dcl_id)) dcl对话框程序(mxb.dcl): xb:dialog{label=/*msg*/″插入明细表″; key=″sd″; :boxed_column { :row { :edit_box{key=″n1″; label=″输入明细表开始序号:″;} } :row { :edit_box{key=″n2″; label=″输入明细表结束序号:″;} } :row{ :edit_box{key=″qa″; label=″请输入比例:″;} } ok_cancel; } } |
|||||||||||||||||