一个简单画图框程序,第一次执行正常,第二次执行,图框的两个矩形重叠
(prompt "\n本程序用于绘制图框,输入命令httk执行。")(defun c:httk()
(setvar "cmdecho" 0)
(if (not (tblsearch "LAYER" "Defpoints"))
(command "-layer" "m" "Defpoints" "")
(command "-layer" "s" "Defpoints" "")
)
(setq num (getint "\n请选择绘制图框大小(0,1,2,3分别对应A0,A1,A1+0.25,A1+0.5):"))
(if (or (< num 0) (> num 3))
(progn (print "输入数值不正确!") (exit))
)
(setq pt (getpoint "\n请指定插入点(默认原点):"))
(if (not pt) (setq pt '(0.0 0.0 0.0)))
(setq colx (getint "\n请输入需要绘制图框的行数(默认:4):"))
(if (not colx) (setq colx 4))
(setq rowy (getint "\n请输入需要绘制图框的列数(默认:1):"))
(if (not rowy) (setq rowy 1))
(cond
((= num 0) (setq a0x 118900.0) (setq a0y 84100.0) (draw_tk pt colx rowy a0x a0y))
((= num 1) (setq a1x 84100.0) (setq a1y 59400.0) (draw_tk pt colx rowy a1x a1y))
((= num 2) (setq a2x 105100.0) (setq a2y 59400.0) (draw_tk pt colx rowy a2x a2y))
((= num 3) (setq a3x 126200.0) (setq a3y 59400.0) (draw_tk pt colx rowy a3x a3y))
)
(command "-layer" "s" "0" "")
(setq pt nil colx nil rowy nil)
(setvar "cmdecho" 1)
(princ)
)
(defun draw_tk (ptt numx numy ax ay / ptt1 ptt2 ptt3 ptt4 ptt5 ptt6 ss ss2 distx disty blockname)
(setq ptt1 ptt)
(setq ptt2 (list (+ (nth 0 ptt1) ax) (+ (nth 1 ptt1) ay) (nth 2 ptt1)))
(setq ptt3 (list (+ (nth 0 ptt1) 2500.0) (+ (nth 1 ptt1) 1000.0) (nth 2 ptt1)))
(setq ptt4 (list (- (nth 0 ptt2) 1000.0) (- (nth 1 ptt2) 1000.0) (nth 2 ptt2)))
(setq ptt5 (list (- (nth 0 ptt2) 8000.0) (- (nth 1 ptt2) 1000.0) (nth 2 ptt2)))
(setq ptt6 (polar ptt5 (* pi 1.5) (- ay 2000.0)))
(command "_rectangle" "w" 0 ptt1 ptt2)
(setq ss (ssadd))
(ssadd (entlast) ss)
;(command "pline" ptt1 "w" 0 0 (polar ptt1 0 ax) ptt2 (polar ptt2 pi ax) "c")
(command "_rectangle" "w" 50 ptt3 ptt4)
(ssadd (entlast) ss)
(command "_line" ptt5 ptt6 "")
(ssadd (entlast) ss)
(setq i 1)
(setq blockname (strcat "b" (itoa i)))
(while (tblsearch "BLOCK" blockname)
(setq i (+ i 1))
(setq blockname (strcat "b" (itoa i)))
)
(command "-block" blockname ptt1 ss "")
(command "-insert" blockname ptt1 "" "" "")
(setq ss2 (ssget "_X" (list '(0 . "insert") (cons 2 blockname))))
(setq distx (* (- (nth 0 ptt2) (nth 0 ptt1)) 2.0))
(setq disty (* (- (nth 1 ptt2) (nth 1 ptt1)) 1.5))
(cond
((and (= numx 1) (> numy 1)) (command "-array" ss2 "" "r" 1 numy distx))
((and (= numy 1) (> numx 1)) (command "-array" ss2 "" "r" numx 1 disty))
((and (> numx 1) (> numy 1)) (command "-array" ss2 "" "r" numx numy disty distx))
((and (= numx 1) (= numy 1)) (print "图框绘制完成!"))
)
)
这段程序,第一次执行正常,第二次执行,图框的两个矩形就重叠了,大佬们帮我看看是哪里出问题了?
把捕捉模式关闭(setvar "osmaode" 0)
osmode,敲错了
谢谢w17063,我试了,没问题了,非常感谢! (setq oldos (getvar "osmode"))
(setvar "osmode" 0) 关闭
(setvar "osmode" oldos) 打开
页:
[1]