明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1430|回复: 5

meflying 请进来帮帮我,谢谢!

[复制链接]
发表于 2004-10-20 16:37:00 | 显示全部楼层 |阅读模式
meflying 这两天我又研究了一下你给我写的程序,当输入的点排完序后,再往里面追加满足条件长方形的四个角点时,当(> lMax l)成立,且有两个相邻点之间夹有两个角点时,循环程序只能在这两点之间追加一个角点。我改了好多次实在是改不明白啊,再请你帮帮忙吧。以下程序中我给定的点是出现的哪种情况,其中注释的哪一点运行时同样出现哪种情况。 (vl-load-com)
(defun c:test( / ent ptLst ptLstc ptLstn pt ptn pti pta j i n dist l lMax)
(setq pt1 '(200 1000 0) pt2 '(400 1000 0) pt3 '(500 0 0) pt4 '(200 0 0) )
;(setq pt1 '(200 1000 0) pt2 '(400 1000 0) pt3 '(2000 500 0) pt4 '(200 0 0) )
(setq ptc1 '(0 1000 0) )
(setq ptc2 '(2000 1000 0) )
(setq ptc3 '(2000 0 0) )
(setq ptc4 '(0 0 0) )
(command "rectang" ptc1 ptc3 "")
(setq ent (entlast))
;*****获取6个点和四个角点部分,根据需要,自己改成你自己的代码******
(setq ptLst (list pt1 pt2 pt3 pt4 ))
(setq ptLstc (list ptc1 ptc2 ptc3 ptc4))
;**************************************************************** (setq ptLst (mapcar '(lambda(x) (list (vlax-curve-getDistAtPoint ent x) x)) ptLst))
(setq ptLst (vl-sort ptLst '(lambda (x1 x2) (< (car x1) (car x2)))))
(setq ptLstc (mapcar '(lambda(x) (list (vlax-curve-getDistAtPoint ent x) x)) ptLstc))
(setq ptLstc (mapcar 'cadr (vl-sort ptLstc '(lambda (x1 x2) (< (car x1) (car x2))))))
(setq i 1)
(repeat 3
(setq dist (append dist (list (- (car (nth i ptLst)) (car (nth (1- i) ptLst))))))
(setq i (1+ i))
)
(setq lMax (apply 'max dist))
(setq l (+ (caar ptLst) (- (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) (car (last ptLst)))))
(if (> lMax l)
(progn
(setq n (vl-position lMax dist))
(repeat (1+ n)
(setq ptLst (reverse (cons (car ptLst) (reverse (cdr ptLst)))))
)
)
)
(setq ptLst (mapcar 'cadr ptLst))
(setq i 0)
(repeat (1- (length ptLst))
(setq pt (nth i ptLst))
(setq ptn (nth (1+ i) ptLst))
(setq ptLstn (append ptLstn (list pt)))
(setq j 0)
(setq m t)
(while m
(setq pti (nth j ptLstc))
(cond
((> (vlax-curve-getDistAtPoint ent pt) (vlax-curve-getDistAtPoint ent ptn))
(if (or (equal (vlax-curve-getStartPoint ent) pti 0.001)
(< (vlax-curve-getDistAtPoint ent pti)(vlax-curve-getDistAtPoint ent ptn))
)
(setq ptLstn (append ptLstn (list pti)))
)
)
((< (vlax-curve-getDistAtPoint ent pt) (vlax-curve-getDistAtPoint ent ptn))
(if (and (> (vlax-curve-getDistAtPoint ent pti) (vlax-curve-getDistAtPoint ent pt))
(< (vlax-curve-getDistAtPoint ent pti) (vlax-curve-getDistAtPoint ent ptn))
)
(setq ptLstn (append ptLstn (list pti)))
)
)
)
(setq j (1+ j))
(if (> j 3) (setq m nil))
)
(setq i (1+ i))
)
(setvar "osmode" 0)
(command "color" 170 "")
(command "_.pline")
(mapcar 'command ptLstn)
(command (last ptLst) "")
(command "color" "bylayer" "")
(command "erase" ent "")
)
 楼主| 发表于 2004-10-21 08:47:00 | 显示全部楼层
谁能帮我把这程序修改一下,我想要的是连线中(0,0,0)点也在连线中,即线条是正交的。
发表于 2004-10-21 10:27:00 | 显示全部楼层
  1. (vl-load-com)
  2. (defun c:test( / ent ptLst ptLstc ptLstn pt ptn pti ptt pta j i n dist l lMax)
  3. ;;;   (setq ent (car (entsel)))
  4. ;;;   
  5. ;;;   ;*****获取6个点和四个角点部分,根据需要,自己改成你自己的代码******
  6. ;;;   (repeat 6
  7. ;;;       (setq ptLst (append ptLst (list (getpoint "\nPick a point:"))))
  8. ;;;   )
  9. ;;;   (repeat 4
  10. ;;;       (setq ptLstc (append ptLstc (list (getpoint "\nPick a point:"))))
  11. ;;;   )
  12. ;;;   ;****************************************************************
  13.    
  14. (setq pt1 '(200 1000 0)   pt2 '(400 1000 0)   pt3 '(500 0 0) pt4 '(200 0 0)   )
  15. ;(setq pt1 '(200 1000 0)   pt2 '(400 1000 0)   pt3 '(2000 500   0) pt4 '(200 0 0)   )
  16. (setq ptc1 '(0 1000 0)   )
  17. (setq ptc2 '(2000 1000 0)   )
  18. (setq ptc3 '(2000 0 0)   )
  19. (setq ptc4 '(0 0 0)   )
  20. (command "rectang" ptc1 ptc3)
  21. (setq ent   (entlast))
  22. ;*****获取6个点和四个角点部分,根据需要,自己改成你自己的代码******
  23. (setq ptLst (list pt1 pt2 pt3 pt4 ))
  24. (setq ptLstc (list ptc1 ptc2 ptc3 ptc4))
  25. ;****************************************************************
  26.    (setq ptLst (mapcar '(lambda(x) (list (vlax-curve-getDistAtPoint ent x) x)) ptLst))
  27.    (setq ptLst (vl-sort ptLst '(lambda (x1 x2) (< (car x1) (car x2)))))
  28.    (setq ptLstc (mapcar '(lambda(x) (list (vlax-curve-getDistAtPoint ent x) x)) ptLstc))
  29.    (setq ptLstc (mapcar 'cadr (vl-sort ptLstc '(lambda (x1 x2) (< (car x1) (car x2))))))
  30.    (setq i 1)
  31.    (repeat 3
  32.        (setq dist (append dist (list (- (car (nth i ptLst)) (car (nth (1- i) ptLst))))))
  33.        (setq i (1+ i))
  34.    )
  35.    (setq lMax (apply 'max dist))
  36.    (setq l (+ (caar ptLst) (- (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) (car (last ptLst)))))
  37.    (if (> lMax l)
  38.        (progn
  39.            (setq n (vl-position lMax dist))
  40.            (repeat (1+ n)
  41.   (setq ptLst (reverse (cons (car ptLst) (reverse (cdr ptLst)))))
  42.            )
  43.        )
  44.    )
  45.    (setq ptLst (mapcar 'cadr ptLst))
  46.    (setq i 0)
  47.    (repeat (1- (length ptLst))
  48.        (setq pt (nth i ptLst))
  49.        (setq ptn (nth (1+ i) ptLst))
  50.        (setq ptLstn (append ptLstn (list pt)))
  51.        (setq j 0)
  52.        (setq m t)
  53.        (while m
  54.            (setq pti (nth j ptLstc))
  55.            (cond
  56.   ((> (vlax-curve-getDistAtPoint ent pt)
  57.          (vlax-curve-getDistAtPoint ent ptn))
  58.    (if (or (equal (vlax-curve-getStartPoint ent) pti 0.001)
  59.      (< (vlax-curve-getDistAtPoint ent pti)
  60.              (vlax-curve-getDistAtPoint ent ptn)
  61.        ))
  62.        (setq ptt (append ptt (list pti)))
  63.    )
  64.    (if (> (vlax-curve-getDistAtPoint ent pti)
  65.    (vlax-curve-getDistAtPoint ent pt)
  66.        )
  67.        (setq ptt (cons pti ptt))
  68.    )
  69.   );1
  70.   ((< (vlax-curve-getDistAtPoint ent pt)
  71.          (vlax-curve-getDistAtPoint ent ptn))
  72.    (if (and (> (vlax-curve-getDistAtPoint ent pti) (vlax-curve-getDistAtPoint ent pt))
  73.        (< (vlax-curve-getDistAtPoint ent pti) (vlax-curve-getDistAtPoint ent ptn)))
  74.        (setq ptt (append ptt (list pti)))
  75.    )
  76.   )
  77.            );cond
  78.            (setq j (1+ j))
  79.            (if (> j 3) (setq m nil))
  80.        )
  81.        (setq ptLstn (append ptLstn ptt))
  82.        (setq ptt nil)
  83.        (setq i (1+ i))
  84.    )
  85.    (setvar "osmode" (logior (getvar "osmode") 16384))
  86.    (command "_.pline")
  87.    (mapcar 'command ptLstn)
  88.    (command (last ptLst) "")
  89. )
 楼主| 发表于 2004-10-22 09:02:00 | 显示全部楼层
谢谢辉哥,让我学到不少东西,总算把这程序看明白了,vlisp里确实有很多好用的命令。(setvar "osmode" (logior (getvar "osmode") 16384)这个用法看你在别的帖子里也发过,真是高人。
发表于 2004-10-22 11:13:00 | 显示全部楼层
一个纯计算型的方法...你先测试一下
  1. (vl-load-com)
  2. (defun Getin(pt1 pt2 ptlst / pt pts i)
  3.    (cond
  4.        ((equal (car pt1) (car pt2) 0.00001) (setq fun 'car))
  5.        ((equal (cadr pt1) (cadr pt2) 0.00001) (setq fun 'cadr))
  6.        (t (princ "Wrong!") (exit))
  7.    )
  8.    (setq i 0)
  9.    (repeat (length ptlst)
  10.        (setq pt (nth i ptlst))
  11.        (if (equal ((eval fun) pt1) ((eval fun) pt) 0.00001)
  12.            (setq pts (cons pt pts))
  13.        )
  14.        (setq i (1+ i))
  15.    )
  16.    (setq pts (mapcar '(lambda (x) (list (distance x pt1) x)) pts))
  17.    (setq pts (vl-sort pts '(lambda (x1 x2) (< (car x1) (car x2)))))
  18.    (setq pts (mapcar 'cadr pts))
  19. )
  20. (defun Getlen (ptlstc ptlst / pt pt1 i len lens lent)
  21.    (setq i 0 len 0)
  22.    (repeat (1- (length ptlst))
  23.        (setq pt (nth i ptlst))
  24.        (setq pt1 (nth (1+ i) ptlst))
  25.        (if (member pt1 ptlstc)
  26.            (setq len (+ len (distance pt pt1)))
  27.            (progn
  28.   (if (= 0 len)
  29.      (setq len (distance pt pt1))
  30.      (setq len (+ len (distance pt pt1)))
  31.   )
  32.   (setq lens (append lens (list len)))
  33.   (setq len 0)
  34.            )
  35.        )
  36.        (setq i (1+ i))
  37.    )
  38.    lens
  39. )
  40. (defun c:test( / ptLst ptLstc pt pt1 pt2 i m n lens)
  41. ;;;   (setq ent (car (entsel)));;;   
  42. ;;;   ;*****获取6个点和四个角点部分,根据需要,自己改成你自己的代码******
  43. ;;;   (repeat 6
  44. ;;;       (setq ptLst (append ptLst (list (getpoint "\nPick a point:"))))
  45. ;;;   )
  46. ;;;   (repeat 4
  47. ;;;       (setq ptLstc (append ptLstc (list (getpoint "\nPick a point:"))))
  48. ;;;   )
  49. ;;;   ;****************************************************************
  50.    
  51. (setq pt1 '(1700 1000 0)
  52.            pt2 '(1800 1000 0)
  53.            pt3 '(500 0 0)
  54.            pt4 '(200 0 0)
  55.            pt5 '(800 0 0)
  56.            pt6 '(1900 1000 0)
  57.            ;(setq pt1 '(200 1000 0)   pt2 '(400 1000 0)   pt3 '(2000 500   0) pt4 '(200 0 0)   )
  58.            ptc1 '(0 1000 0)
  59.            ptc2 '(2000 0 0)
  60.            ptc3 '(2000 1000 0)
  61.            ptc4 '(0 0 0))
  62. ;*****获取6个点和四个角点部分,根据需要,自己改成你自己的代码******
  63.    (setq ptLst (list pt1 pt2 pt3 pt4 pt5 pt6))
  64.    (setq ptLstc (list ptc1 ptc2 ptc3 ptc4))
  65.    (setq i 1)
  66.    (setq pt1 (list (car ptlstc))   ptlstc (vl-remove (car pt1) ptlstc))
  67.    (while (> (length ptlstc) 0)
  68.        (setq pt (car ptlstc))
  69.        (if (or (equal (car pt) (caar pt1) 0.00001)
  70.          (equal (cadr pt) (cadar pt1) 0.00001))
  71.            (setq pt1 (cons pt pt1) ptlstc (vl-remove (car pt1) ptlstc))
  72.            (setq ptlstc (append (cdr ptlstc) (list (car ptlstc))))
  73.        )
  74.    )
  75.    (setq ptlstc pt1)
  76.    (setq ptlstc (append ptlstc (list (car ptlstc))))
  77.    (setq i 0 pt2 nil)
  78.    (repeat 4
  79.        (setq pt (nth i ptlstc)
  80.      pt1 (nth (1+ i) ptlstc))
  81.        (setq pt2 (append pt2 (cons pt (Getin pt pt1 ptlst))))
  82.        (setq i (1+ i))
  83.    )
  84.    (setq ptlst pt2)
  85.    (while (member (car ptlst) ptlstc)
  86.        (setq ptlst (cons (last ptlst) (reverse (cdr (reverse ptlst)))))
  87.    )
  88.    (setq ptlst (append ptlst (list (car ptlst))))
  89.    (setq lens (getlen ptlstc ptlst))
  90.    (setq n (vl-position (apply 'max lens) lens))
  91.    (setq i 0 m 0)
  92.    (while (<= m (1+ n))
  93.        (setq pt (nth i ptlst))
  94.        (if (not (member pt ptlstc))
  95.            (setq m (1+ m))
  96.        )
  97.        (setq i (1+ i))
  98.    )
  99.    (setq ptlst (reverse (cdr (reverse ptlst))))
  100.    (repeat (1- i)
  101.        (setq ptlst (append (cdr ptlst) (list (car ptlst))))
  102.    )
  103.    (while (member (car ptlst) ptlstc) (setq ptlst (cdr ptlst)))
  104.    (while (member (last ptlst) ptlstc) (setq ptlst (reverse (cdr (reverse ptlst)))))
  105.    
  106.    (setvar "osmode" (logior (getvar "osmode") 16384))
  107.    (command "_.pline")
  108.    (mapcar 'command ptLst)
  109.    (command "")
  110. )
 楼主| 发表于 2004-10-22 19:46:00 | 显示全部楼层
好啊,辉哥,你效率真高啊。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-18 11:33 , Processed in 0.186949 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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