明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[源码] 一个简单的多段线打断,补充凸度

[复制链接]
发表于 2023-6-18 10:05:28 | 显示全部楼层
xyp1964 发表于 2023-6-14 12:17
(defun c:tt ()
  "单点打断"
  (while (setq ent (entsel "\n选择打断对象: "))

大佬的代码总是这么的简洁好用,感谢~
发表于 2023-8-22 17:53:30 | 显示全部楼层
试了一下,写了个逻辑比较混乱的,好多bug欢迎扔砖


  1. ;;;打断LWPLINE逻辑混乱版
  2. (defun c:tt  (/         xty-L-cdrn   xty-L-carn
  3.         xty-L-retainget-vtxl   xty-tan  make-pl  bu
  4.         bue      bus  en   en1    en2     enl
  5.         enn      ent  fuzz   ince    incs     mode
  6.         ne       ns  ocs   pme    pms     pt
  7.         pta      ptb  ptl   tmp    vtx1     vtx2
  8.         vtxe     vtxl  vtxs   vtxt    we     wee
  9.         wes      ws  wse   wss    x)
  10.     (defun xty-L-cdrn  (n lst /)
  11.   (if (= 0 n)
  12.       lst
  13.       (repeat n (setq lst (cdr lst)))
  14.       )
  15.   )
  16.     (defun xty-L-carn  (n lst / lsta)
  17.   (if (= 0 n)
  18.       (setq lsta lst)
  19.       (progn (setq lsta nil)
  20.        (repeat n
  21.            (setq lsta (append lsta (list (car lst)))
  22.            lst  (cdr lst)
  23.            )
  24.            )
  25.        )
  26.       )
  27.   lsta
  28.   )
  29.     (defun xty-L-retain   (m n lst /)
  30.   (setq lst (xty-L-carn n lst))
  31.   (setq lst (if (= 1 m)
  32.           lst
  33.           (xty-L-cdrn (1- m) lst)
  34.           )
  35.         )
  36.   )
  37.     (defun xty-tan  (ang)
  38.   ((lambda (x)
  39.        (if (equal 0. x 1e-14)
  40.      nil
  41.      (/ (sin ang) x)
  42.      )
  43.        )
  44.       (cos ang)
  45.       )
  46.   )
  47.     (defun xty-L-delsames  (lst fuzz / start new)
  48.   (while (setq start (car lst))
  49.       (if  (vl-some '(lambda (x) (equal start x fuzz)) new)
  50.     nil
  51.     (setq new (cons start new))
  52.     )
  53.       (setq lst (cdr lst))
  54.       )
  55.   (setq new (reverse new))
  56.   new
  57.   )
  58.     (defun get-vtxl  (ent / vtxl)
  59.   (while (setq ent (member (assoc 10 ent) ent))
  60.       (setq vtxl (cons (list (assoc 10 ent)
  61.            (assoc 40 ent)
  62.            (assoc 41 ent)
  63.            (assoc 42 ent))
  64.            vtxl)
  65.       ent  (cdr ent)))
  66.   (reverse vtxl))
  67.     (defun make-pl  (tmp ent ocs)
  68.   (entmakex
  69.       (append (subst (cons 90 (length tmp)) (assoc 90 ent) ent)
  70.         (apply 'append tmp)
  71.         (list (cons 210 ocs)))))
  72.     (setq fuzz 1e-6
  73.     en   (car (entsel))
  74.     ent  (entget en)
  75.     ocs  (cdr (assoc 210 ent))
  76.     vtxl (get-vtxl ent)
  77.     mode (if (= 1 (cdr (assoc 70 ent)))
  78.        t
  79.        nil)
  80.     vtxl (if (equal (caar vtxl) (car (last vtxl)) fuzz)
  81.        (reverse (cdr (reverse vtxl)))
  82.        vtxl)
  83.     ptl  nil)
  84.     (while (setq pt (getpoint)) (setq ptl (cons pt ptl)))
  85.     (setq ptl (mapcar '(lambda (x) (trans x 1 0)) ptl)
  86.     pta (vlax-curve-getstartpoint en)
  87.     ptb (vlax-curve-getendpoint en)
  88.     ptl (cons pta ptl)
  89.     ptl (cons ptb ptl)
  90.     ptl (xty-l-delsames ptl fuzz)
  91.     ptl (vl-sort
  92.       ptl
  93.       (function (lambda (x y)
  94.         (< (vlax-curve-getparamatpoint en x)
  95.            (vlax-curve-getparamatpoint en y)))))
  96.     ptl (if (equal pta ptb fuzz)
  97.       (append ptl (list ptb))
  98.       ptl)
  99.     )
  100.     (setq ent (reverse (member (assoc 39 ent) (reverse ent))))
  101.     (setq ent
  102.        (vl-remove-if
  103.      '(lambda (x)
  104.           (member (car x) '(-1 5 6 8 39 43 48 62 102 330 370)))
  105.      ent))
  106.     (setq ent (subst (cons 70 0) (assoc 70 ent) ent))
  107.     (setq enl (mapcar
  108.       (function
  109.           (lambda (pts pte)
  110.         (setq  pms  (vlax-curve-getparamatpoint
  111.            en
  112.            pts)
  113.         ns   (fix pms)
  114.         incs (- pms ns)
  115.         vtxs (nth ns vtxl)
  116.         pme  (vlax-curve-getparamatpoint
  117.            en
  118.            pte)
  119.         pme  (if (< pme pms)
  120.            (vlax-curve-getendparam en)
  121.            pme)
  122.         pme  (if (> pme (length vtxl))
  123.            (- pme 1)
  124.            pme)
  125.         pme  (if (= pme (length vtxl))
  126.            (1- pme)
  127.            pme)
  128.         ne   (fix pme)
  129.         ince (- pme ne)
  130.         vtxe (nth ne vtxl)
  131.         wss  (cdr (assoc 40 vtxs))
  132.         wse  (cdr (assoc 41 vtxs))
  133.         bus  (atan (cdr (assoc 42 vtxs)))
  134.         wes  (cdr (assoc 40 vtxe))
  135.         wee  (cdr (assoc 41 vtxe))
  136.         bue  (atan (cdr (assoc 42 vtxe))))
  137.         (if (= ns ne)
  138.             (setq ws   (+ wss (* incs (- wse wss)))
  139.             we   (+ wss (* ince (- wse wss)))
  140.             bu   (xty-tan (* (- pme pms) bus))
  141.             vtxs (list
  142.                (cons 10
  143.                (trans pts 0 ocs))
  144.                (cons 40 ws)
  145.                (cons 41 we)
  146.                (cons 42 bu))
  147.             vtxe (list
  148.                (cons 10
  149.                (trans pte 0 ocs))
  150.                (cons 40 we)
  151.                (cons 41 we)
  152.                (cons 42 bu))
  153.             enn   (make-pl (list vtxs vtxe)
  154.               ent
  155.               ocs))
  156.             (setq ws   (+ wss (* incs (- wse wss)))
  157.             bu   (- (xty-tan (* (1- incs) bus)))
  158.             vtxs (list
  159.                (cons 10
  160.                (trans pts 0 ocs))
  161.                (cons 40 ws)
  162.                (cons 41 wse)
  163.                (cons 42 bu))
  164.             ws   (+ wes (* ince (- wee wes)))
  165.             bu   (xty-tan (* (- pme ne) bue))
  166.             tmp   (xty-L-retain (+ ns 2)
  167.                    (1+ ne)
  168.                    vtxl)
  169.             vtxt (last tmp)
  170.             tmp   (reverse (cdr (reverse tmp)))
  171.             vtxt (subst  (cons 41 ws)
  172.             (assoc 41 vtxt)
  173.             vtxt)
  174.             vtxt (subst  (cons 42 bu)
  175.             (assoc 42 vtxt)
  176.             vtxt)
  177.             vtxe (list
  178.                (cons 10
  179.                (trans pte 0 ocs))
  180.                (cons 40 wee)
  181.                (cons 41 wee)
  182.                (cons 42 bu))
  183.             tmp   (cons vtxs tmp)
  184.             enn   (make-pl
  185.                (append tmp
  186.                  (list vtxt vtxe))
  187.                ent
  188.                ocs)))))
  189.       ptl
  190.       (cdr ptl)))
  191.     (if  mode
  192.   (progn (setq en1  (car enl)
  193.          vtx1 (get-vtxl (entget en1))
  194.          en2  (last enl)
  195.          vtx2 (get-vtxl (entget en2))
  196.          enl  (vl-remove en1 enl)
  197.          enl  (vl-remove en2 enl)
  198.          enl  (cons  (make-pl (append vtx2 (cdr vtx1)) ent ocs)
  199.         enl))
  200.          (entdel en1)
  201.          (entdel en2))))

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2023-11-6 17:20:37 | 显示全部楼层
xyp1964 发表于 2023-6-14 12:17
(defun c:tt ()
  "单点打断"
  (while (setq ent (entsel "\n选择打断对象: "))

这个是方便,但是如果是闭合的多段线,使用这个程序打断的话会变成2条多段线。
发表于 2023-11-6 19:11:20 | 显示全部楼层
ashan 发表于 2023-11-6 17:20
这个是方便,但是如果是闭合的多段线,使用这个程序打断的话会变成2条多段线。

闭合的非要打断本身就不正常……
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-27 19:18 , Processed in 0.128168 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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