明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1291|回复: 8

运行有时正确有时不正确,特请教!

[复制链接]
发表于 2005-5-14 17:43 | 显示全部楼层 |阅读模式
我编了一个程序,目的是把多条井字形的水平线,垂直线剪切成田字形;运行时出现很奇怪的情况,对同一个图形,剪切有时正确有时错误,程序如下,请高手指点(程序虽然长一些,但思路简单):(defun C:fe()
;(setvar "cmdecho" 0)
(setq oldos (getvar "osmode"))
(setq oldortho (getvar "orthomode"))
(setvar "osmode" 0)
(setvar "orthomode" 1)
(command "ucs" "w" "")
(setq ss (ssget))
(setq nn (sslength ss))
(setq pt (getpoint "\npick a point")
x-pt(x-coordinate pt)
y-pt(y-coordinate pt))

(setq na 0)
(while (or (= x-line nil)(= y-line nil))
(setq ssna (ssname ss na))
(if (= (cdr (assoc 0 (entget ssna))) "XLINE")
(if (= (cadr (assoc 11 (entget ssna))) 1.0)
(setq y-line (caddr (assoc 10 (entget ssna))))
(setq x-line (cadr (assoc 10 (entget ssna))))
);_end of if
)
(if (= (cdr (assoc 0 (entget ssna))) "RAY")
(if (or(= (cadr (assoc 11 (entget ssna))) 1.0)
(= (cadr (assoc 11 (entget ssna))) -1.0)
);_end of or
(setq y-line (caddr (assoc 10 (entget ssna))))
(setq x-line (cadr (assoc 10 (entget ssna))))
);_end of if

)
(if (= (cdr (assoc 0 (entget ssna))) "LINE")
(progn (setq lpt0 (cdr (assoc 10 (entget ssna)))
lpt1 (cdr(assoc 11 (entget ssna)))
x-lpt0 (x-coordinate lpt0)
y-lpt0 (y-coordinate lpt0)
x-lpt1 (x-coordinate lpt1)
y-lpt1 (y-coordinate lpt1)
);_end of setq
(if (equal x-lpt0 x-lpt1 1e-4)(setq x-line x-lpt0))
(if (equal y-lpt0 y-lpt1 1e-4)(setq y-line y-lpt0))
);_end of progn
);_end of if

(setq na(1+ na))
);_end of while
(setq xmin x-line
xmax x-line
ymin y-line
ymax y-line
)

(setq na 0)
(while (< na nn)
(setq ssna (ssname ss na))
(if (= (cdr (assoc 0 (entget ssna))) "XLINE")
(if (= (cadr (assoc 11 (entget ssna))) 1.0)
(setq y-line (caddr (assoc 10 (entget ssna))))
(setq x-line (cadr (assoc 10 (entget ssna))))
);_end of if
)
(if (= (cdr (assoc 0 (entget ssna))) "RAY")
(if (or (= (cadr (assoc 11 (entget ssna))) 1.0)
(= (cadr (assoc 11 (entget ssna))) -1.0)
);_end of or
(setq y-line (caddr (assoc 10 (entget ssna))))
(setq x-line (cadr (assoc 10 (entget ssna))))
);_end of if
);_end of if
(if (= (cdr (assoc 0 (entget ssna))) "LINE")
(progn (setq lpt0 (cdr (assoc 10 (entget ssna)))
lpt1 (cdr (assoc 11 (entget ssna)))
x-lpt0 (x-coordinate lpt0)
y-lpt0 (y-coordinate lpt0)
x-lpt1 (x-coordinate lpt1)
y-lpt1 (y-coordinate lpt1)
);_end of setq
(if (equal x-lpt0 x-lpt1 1e-4)(setq x-line x-lpt0))
(if (equal y-lpt0 y-lpt1 1e-4)(setq y-line y-lpt0))
);_end of progn
);_end of if
(if (< x-line xmin)(setq xmin x-line))
(if (> x-line xmax)(setq xmax x-line))
(if (< y-line ymin)(setq ymin y-line))
(if (> y-line ymax)(setq ymax y-line))
(setq na(1+ na))
);_end of while
(if (or (< x-pt xmin) (> x-pt xmax)(< y-pt ymin)(> y-pt ymax))
(progn (setq xmin (- xmin 2.0)
xmax (+ xmax 2.0)
ymin (- ymin 2.0)
ymax (+ ymax 2.0)
);_end of setq
);_end of progn
(progn (setq xmin (+ xmin 2.0)
xmax (- xmax 2.0)
ymin (+ ymin 2.0)
ymax (- ymax 2.0)
);_end of setq
);_end of progn
);_end of if
(setq ptt1(list xmin ymin 0.0)
ptt2(list xmax ymin 0.0)
ptt3(list xmax ymax 0.0)
ptt4(list xmin ymax 0.0))
; (setq Ptt5 (list (- xmin 30.0) (- ymin 30.0) 0.0)
; ptt6 (list (+ xmax 30.0)(+ ymax 30.0) 0.0))
;(command "zoom" "w" ptt5 ptt6)

(command "trim" ss "" "f" ptt1 ptt2 "" "f" ptt2 ptt3 "" "f" ptt3 ptt4 "" "f" ptt4 ptt1 "" "")

(setvar "cmdecho" 1)
(setvar "osmode" oldos)
(setvar "orthomode" oldortho)
(princ "\n2005-4-21")
(princ)
)
发表于 2005-5-14 22:55 | 显示全部楼层
你首先应该定义一下X-COORDINATE和y-coordinate这两个函数啊!其他的就没有看了,不过LiSP程序我觉得调试还是应该用R14吧(本人观点,相信其他人也有同感吧),只要在R14通过了,大概在其他版本中也就可以了,再说出错处在R14下基本一目了然了!
 楼主| 发表于 2005-5-15 18:25 | 显示全部楼层
(defun x-coordinate(pt)
(car pt))
(defun Y-coordinate(pt)
(cadr pt)) 仅仅是两个用于取得点的X,Y坐标的函数。上面的问题困拢我很久,这个函数一直运行不稳定,非常希望高手指点.
发表于 2005-5-15 21:12 | 显示全部楼层
那你试着定义一下看看嘛
发表于 2005-5-15 22:52 | 显示全部楼层
看不懂
发表于 2005-5-16 08:39 | 显示全部楼层
TRIM就是这样,就象你平时使用,图如果缩小了,你也很难用鼠标选中你想选的部分,
 楼主| 发表于 2005-5-16 11:37 | 显示全部楼层
那是不是要定义pickbox和zoom,能否请教一下如何定义能得到合适的结果
发表于 2005-5-16 11:57 | 显示全部楼层
你试试使用点表,,


就是trim使用点选择对象的时候,不要直接输入点,而使用(cons ent pt),pt就是你原来打算直接用的,ent就是你想要选中的对象,这样,就不会选到别的对象上面去了
发表于 2005-5-16 12:07 | 显示全部楼层
(progn (setq xmin (- xmin 2.0)
这句和下面那句,我感觉这个2.0定义的不太合理,应该尽可能小,当某一条线超出边界小于2.0时,这个程序就剪不掉了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-1 19:54 , Processed in 0.309409 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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