- UID
- 215303
- 积分
- 73
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-1-30
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2005-4-3 19:30:52
|
显示全部楼层
还是自己写了个,初次写程序,希望大家给修改一下,程序运行的结果是:选择一个点(只能是边上的点)得到路由上的任何一点到该点的路由:
(defun c:test()
(vl-load-com)
(setq aline (ssget "X" '((0 . "*LINE"))) )
(bleakpline aline)
(setq aline (ssget "X" '((0 . "*LINE"))) )
(bleakp aline)
(setq aline (ssget "X" '((0 . "*LINE"))) )
(getzonglist aline);得到APINT
(zhenlilist APINT);得到APINT
(setq p1 (getpoint "选择点..."))
(setq p1 (list (atof (rtos (car p1) 2 0))
(atof (rtos (cadr p1) 2 0))
))
(setq i 0 aplist '())
(while (< i (length apint))
(if (equal (car (nth i apint)) p1)
(setq aplist (cons (nth i apint) aplist))
)
(setq i (1+ i))
)
(setq aaa aplist aplist nil)
(setq bbb apint aplist nil)
(gettlist aaa bbb)
(setq lastlist plist)
(princ)
)
(defun zhenlilist(aline /);整理表 保留整数
(setq i 0)
(setq llst apint)
(setq apint '())
(while (< i (length llst))
(setq ename1x (car (nth 0 (nth i llst))))
(setq ename1y (cadr (nth 0 (nth i llst))))
(setq ename2x (car (nth 1 (nth i llst))))
(setq ename2y (cadr (nth 1 (nth i llst))))
(setq newxy (list (list (atof (rtos ename1x 2 0)) (atof (rtos ename1y 2 0)))
(list (atof (rtos ename2x 2 0)) (atof (rtos ename2y 2 0))))
)
(setq apint (cons newxy apint))
(setq i (1+ i))
)
(princ)
)
(defun getzonglist(aline /);取得所有线的交点并组成表
(setq i 0 apint '())
(while (< i (sslength aline))
(setq ename (ssname aline i))
(vertexs ename)
(setq apint (cons pp apint))
(setq apint (cons (reverse pp) apint))
(setq i (1+ i))
)
(princ)
)
(defun bleakp(aline /);以线的交点打断
(setq i 0 )
(while (< i (sslength aline))
(setq one (ssname aline i))
(setq n 0)
(while (< n (sslength aline))
(setq two (ssname aline n))
(if (/= n i) (GetInterPoint one two))
(setq n (1+ n))
)
(setq i (1+ i))
)
(princ)
)
(defun bleakpline(aline /);打断多义线的各个顶点
(setq ssa aline alist '())
(setq i 0)
(while (< i (sslength ssa))
(setq ename (ssname ssa i))
(vertexs ename)
(setq k 0)
(repeat (length pp)
(setq ppt (nth k pp))
(COMMAND "break" ppt ppt)
(setq k (1+ k))
)
(setq i (1+ i))
)
(princ)
)
;得到所有多段线的各个顶点的坐标
(defun vertexs (ename /)
(vl-load-com)
(setq obj (vlax-ename->vla-object ename))
(setq plist (vlax-safearray->list
(vlax-variant-value
(vla-get-coordinates obj)
)
)
)
(setq n 0 pp '())
(repeat (/ (length plist) 2)
(setq pp (append pp (list (list (nth n plist) (nth (1+ n) plist)))))
(setq n (+ n 2))
)
(princ)
)
;得到2根曲线的交点坐标,并打断该线。
(defun GetInterPoint (ent_1 ent_2 / ent1 ent2
ax_ent_1 ax_ent_2 intpoints i
j k disp
)
;(setq ent1 (entsel "\n选择第一条曲线:"))
;(setq ent2 (entsel "\n选择第二条曲线:"))
;(setq ent_1 (car ent1)
; ent_2 (car ent2)
;)
(setq ax_ent_1 (vlax-ename->vla-object ent_1)
ax_ent_2 (vlax-ename->vla-object ent_2)
)
(setq intpoints (vla-intersectwith ax_ent_1 ax_ent_2 acextendnone))
(setq intpoints (vlax-variant-value intpoints))
(if (> (vlax-safearray-get-u-bound intpoints 1) 0)
(progn
(setq i 0)
(setq j 0)
(setq k 0 cp nil)
(repeat (/ (+ 1 (- (vlax-safearray-get-u-bound intpoints 1) (vlax-safearray-get-l-bound intpoints 1)))3)
(setq cp (list (vlax-safearray-get-element intpoints j)
(vlax-safearray-get-element intpoints (+ 1 j))
(vlax-safearray-get-element intpoints (+ 2 j))
)
)
(COMMAND "_break" ent_1 cp cp);打断该线
(COMMAND "_break" ent_2 cp cp);打断该线
(setq i (+ 2 i)
j (+ 3 j)
k (+ 1 k)
)
)
)
)
(princ)
)
(defun gettlist(aplist apint /);得到路由表。
(setq p apint)
(setq plist (list aplist))
(setq ss (list (caar aplist)))
(REPEAT 10
(setq k 0 )
(setq temlist plist)
(WHILE (< k (LENGTH temlist))
(setq one (cadr (last (nth k temlist))))
(seelist one ss)
(if (= jie "n" )
(progn
(getlist (nth k temlist) one )
(setq r 0 )
(while (< r (length alist))
(setq plist (cons (nth r alist) plist))
(setq r (1+ r))
)
(setq ss (cons one ss))
)
)
(setq k (1+ k))
)
)
(princ)
)
;(setq pp (nth k temlist))
;(setq yuan one)
(defun getlist (pp yuan /);根据一个路由表的最后一个点判断后面是否有点有的话增加。
(setq m 0 alist '())
(WHILE (< m (LENGTH p))
;(bijiao yuan (car (nth m p)))
;(if (= tr "t")
(if (equal yuan (car (nth m p)))
(if (equal (REVERSE (last pp)) (nth m p))
(setq dshfi 'sdilfuhg)
(progn
(setq ttlist '())
(setq ttlist (REVERSE (cons (nth m p) (REVERSE pp))))
(setq alist (cons ttlist alist ))
)
)
)
(setq m (1+ m))
)
(princ)
)
(defun seelist (item lst /);比较两个表是否相同
(setq m 0 jie "n" )
(while (< m (length ss))
(if (equal item (nth m ss))
(setq jie "t" )
)
(setq m (1+ m))
)
(princ)
)
这里有个问题就是,打断了线,而且没有考虑到曲线,还有一个坐标比较的时候直接比较好像老是不对,所以就改用保留2位小数, 我主要是考虑这个思路对不对,对好的话就可以继续改了,如果不对各位就指点一下,我的QQ156558475 |
|