明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 478|回复: 4

[讨论] 一个简单画图框程序,第一次执行正常,第二次执行,图框的两个矩形重叠

[复制链接]
发表于 2023-12-13 09:58 | 显示全部楼层 |阅读模式
(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 "图框绘制完成!"))
       )
)

这段程序,第一次执行正常,第二次执行,图框的两个矩形就重叠了,大佬们帮我看看是哪里出问题了?

发表于 2023-12-13 10:19 | 显示全部楼层
把捕捉模式关闭(setvar "osmaode" 0)
发表于 2023-12-13 10:20 | 显示全部楼层
osmode,敲错了
 楼主| 发表于 2023-12-13 10:32 | 显示全部楼层
谢谢w17063,我试了,没问题了,非常感谢!
 楼主| 发表于 2023-12-13 11:34 | 显示全部楼层
       (setq oldos (getvar "osmode"))
       (setvar "osmode" 0) 关闭
       (setvar "osmode" oldos) 打开
      
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-14 00:19 , Processed in 0.157733 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表