明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1512|回复: 1

[LISP]请帮我的程序指出错误

[复制链接]
发表于 2004-6-10 10:39:00 | 显示全部楼层 |阅读模式
我的程序是在选择的边界内部间隔10米画一个圆。我的大致思想是在选择边界后,在选择一内部点。然后用一个二重循环得到点。在点 画圆。点的得到是在内部点的基础上分x和y累加累减,用一个测试在内部的函数(zn)来控制循环的结束。但是我的程序不能运用,不知道问题出在那里。请大家帮帮忙,在此谢谢了!!! (defun c:tc()
(defun zn (/ plendpt x_lst e op
n fst_pt int_num online pc
pn min_num edge_int_num pt_online_num
op1 )
(setq min_num 0.0001)
(princ "\n选择边界:")
(while (not e) (setq e (car (entsel))))
(if (= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
(progn
(redraw e 3)
(while (not op) (setq op (getpoint "\n请拾取边界内部点:")))
(foreach n (entget e)
(if (= 10 (car n))
(if plendpt
(setq plendpt (append plendpt (list (cdr n))))
(setq plendpt (list (cdr n)))
)
)
)
(setq X_lst (mapcar '(lambda (x) (car x)) plendpt))
(setq delta_X (abs (- (apply 'max x_lst) (car op))))
(setq plendpt (append plendpt (list (nth 0 plendpt)))
edge_int_num 0
pt_online_num 0
)
(while (> (length plendpt) 1)
(setq pc (nth 0 plendpt)
pn (nth 1 plendpt)
)
(setq op1 (polar op 0 (* delta_x 2)))
(if (inters op
op1
pc
pn
) (setq edge_int_num (+ 1 edge_int_num))
)
(if (equal (+ (distance op pc) (distance pc op1))
(distance op op1)
min_num)
(setq pt_online_num (+ 1 pt_online_num))
) (if (equal (+ (distance op pc) (distance op pn))
(distance pc pn)
min_num
)
(setq online "t")
)
(setq plendpt (cdr plendpt))
)
(redraw e 4)

)
)
)
(setq x (car p0))
(setq y (cadr p0))
(zn)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(zn)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(command "circle" p0 1 "" )
(setq x (+ x 10))
(setq p0 (list x y))
) (setq y (+ y 10))
(setq p0 (list x y))
(command "circle" p0 1 "" )
)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(zn)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(command "circle" p0 1 "" )
(setq x (+ x 10))
(setq p0 (list x y))
) (setq y (- y 10))
(setq p0 (list x y))
(command "circle" p0 1 "" )
)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(zn)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(command "circle" p0 1 "" )
(setq x (- x 10))
(setq p0 (list x y))
) (setq y (+ y 10))
(setq p0 (list x y))
(command "circle" p0 1 "" )
)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(zn)
(while (= (rem (+ pt_online_num edge_int_num) 2) 1)
(command "circle" p0 1 "" )
(setq x (- x 10))
(setq p0 (list x y))
) (setq y (- y 10))
(setq p0 (list x y))
(command "circle" p0 1 "" )
) )

发表于 2004-6-10 10:50:00 | 显示全部楼层
注意:        edge_int_num                                         pt_online_num这两个变量是zn函数的局部变量,离开这个函数后,这个变量就不存在了,所以你主函数的同样名字的两个变量跟ZN函数里这两个变量是没有关系的,这样就导致主函数中的变量没有赋值。。。


另:(setq X_lst (mapcar 'car plendpt));这里这样就可以了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-6 09:45 , Processed in 0.163891 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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