明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: chwnin

[基础] 请问大家快速选择首尾相连的所有线段,如何用lisp实现啊

[复制链接]
发表于 2013-10-23 00:04:38 | 显示全部楼层
没办法。你看gu_xl版主的这个吧。
http://bbs.mjtd.com/forum.php?mo ... &fromuid=338795
  1. ;;选择直线相连 By Gu_xl
  2. (defun c:tt(/ gxl-Sel-ReDrawSel gxl-Sel-SSsub gxl-Sel-SSJoin gxl-sel-SSgetLineatPoint getline)
  3.   (defun gxl-Sel-ReDrawSel (Sel mode / m n)
  4.     (setq m (sslength Sel)
  5.    n 0)
  6.     (repeat m
  7. (redraw (ssname Sel n) mode)
  8. (setq n (1+ n))
  9. );repeat
  10.     )
  11.   (defun gxl-Sel-SSsub(ss1 ss2 / ss n)
  12. (cond
  13. ((and ss1 ss2)
  14.   (setq n 0)
  15.   (repeat (sslength ss2)
  16.     (ssdel (ssname ss2 n) ss1)
  17.     (setq n (1+ n))
  18.     )
  19. )
  20. ((and ss1 (not ss2))
  21.   ss1
  22. )
  23. (T
  24.   (setq ss1 nil)
  25. )
  26. )
  27. ss1
  28. )
  29.   (defun gxl-Sel-SSJoin ( ss1 ss2 / ename ss cnt )
  30. (if ss1
  31. (progn
  32. (if (= (type ss1) 'ENAME)
  33. (progn
  34.   (setq
  35.    ename ss1
  36.    ss1   (ssadd)
  37.   )
  38.   (ssadd ename ss1)
  39. ))
  40. ))
  41. (if ss2
  42. (progn
  43. (if (= (type ss2) 'ENAME)
  44. (progn
  45.   (setq
  46.    ename ss2
  47.    ss2   (ssadd)
  48.   )
  49.   (ssadd ename ss2)
  50. ))
  51. ))
  52. (setq ss (ssadd))
  53. (if (and ss1 ss2)
  54. (progn
  55. ;(setq ss ss2 cnt 0)
  56.         (setq  cnt 0)
  57.         (repeat (sslength ss2)
  58.   (ssadd (ssname ss2 cnt) ss)
  59.   (setq cnt (1+ cnt))
  60. )
  61.         (setq  cnt 0)
  62. (repeat (sslength ss1)
  63.   (ssadd (ssname ss1 cnt) ss)
  64.   (setq cnt (1+ cnt))
  65. )
  66. ))
  67. (if (and ss1 (not ss2))
  68. (setq ss ss1))
  69. (if (and ss2 (not ss1))
  70. (setq ss ss2))
  71. (if (> (sslength ss) 0)
  72.   ;;(eval ss)
  73. ss
  74. nil
  75. )
  76. )
  77.   (defun gxl-sel-SSgetLineatPoint (pt jd /  px py px0 px1 py0 py1 ss  pz)
  78. (setq px (car pt)
  79.       px0 (- px jd)
  80.       px1 (+ px jd)
  81.       py (cadr pt)
  82.       py0 (- py jd)
  83.       py1 (+ py jd)
  84.       pz (caddr pt)
  85.       )
  86.   (setq ss
  87. (ssget "x" (list '(0 . "line")
  88.    '(-4 . "<or")

  89.    '(-4 . "<and")
  90.    '(-4 . ">=,>=,=")
  91.    (list 10 px0 py0 pz)
  92.    '(-4 . "<=,<=,=")
  93.    (list 10 px1 py1 pz)
  94.    '(-4 . "and>")
  95.    
  96.    '(-4 . "<and")
  97.    '(-4 . ">=,>=,=")
  98.    (list 11 px0 py0 pz)
  99.    '(-4 . "<=,<=,=")
  100.    (list 11 px1 py1 pz)
  101.    '(-4 . "and>")
  102.    
  103.    '(-4 . "or>")
  104.    )
  105.        )
  106.   )
  107.   (if ss(GXL-SEL-REDRAWSEL ss 3))
  108.   ss
  109.   )
  110.   (defun getline (pt jd / s s1 n p1 p2)
  111.    
  112.     (setq s (gxl-sel-SSgetLineatPoint pt jd))
  113.     (if s
  114.       (progn
  115. (setq s1 (GXL-SEL-SSSUB s ssrtl)
  116.        ssrtl (GXL-SEL-SSJOIN ssrtl s1)
  117.        )

  118. (if s1
  119.    (progn
  120.      (setq n 0)
  121.      (repeat (sslength s1)
  122.        (setq p1 (cdr (assoc 10 (entget (ssname s1 n))))
  123.       p2 (cdr (assoc 11 (entget (ssname s1 n))))
  124.       )
  125.        (getline p2 jd)
  126.        (getline p1 jd)
  127.        (setq n (1+ n))
  128.        )
  129.      )
  130.    )
  131. )
  132.       )
  133.    
  134.     )
  135.   ;;;程序开始
  136.     (princ "\n选择直线:")
  137.   (setq enline (car (entsel)))
  138.   (initget 5 "  ")
  139.   (setq jd (getreal "输入容差精度:<0.001>"))
  140.   (if (= jd "")(setq jd 0.001))
  141.   (setq pt1 (cdr (assoc 10 (entget enline))))
  142.   (setq pt2 (cdr (assoc 11 (entget enline))))
  143. (setq ssrtl (ssadd enline))
  144.   (getline pt1 jd)
  145.   (getline pt2 jd)
  146.   (sssetfirst nil ssrtl)
  147.   )
发表于 2013-10-23 12:53:12 | 显示全部楼层
G版的程式可以实现。
 楼主| 发表于 2013-10-24 11:57:16 | 显示全部楼层
已OK,但要把多段线改为直线
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-26 05:43 , Processed in 0.150990 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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