乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 60|回复: 18

[编程交流] 将直线分解为线段

[复制链接]

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-5 23:56:14 | 显示全部楼层 |阅读模式
你好
 
我的最终目的是生成一个例程,将直线分解为由交点定义的线段。(见jpg附件)
 
我的需求:
 
[列表=1]
  • 填充不相交的垂直线之间的间隙(我发现只有pedit可以这样做)
  • 运行扫描以验证仍然不相交的垂直线(我再次分解多段线,因为(inters)仅适用于线)
  • 在每个交点上运行(中断)(特征)
  • 运行一个函数,收集长度小于x的所有行,并删除它们(特征)
  • (仍需考虑保护某些线路免受上述功能影响的方法)(功能)
    [/列表]
     
     
    现在,我得到了选择集,我把线连接成一条多段线,现在为了使用9inters)函数,我需要将无间隙的多段线转换回线
     
    但使用时:
    1. (command "_.explode" entlast "")

     
    我出错了
     
    我做错了什么?
     
    1. (defun C:TEST (/ st cen my mx z i)
    2. (setq ope (getvar "PEDITACCEPT"))
    3. (if (setq st (ssget '((0 . "LINE"))));_ get a selectio set
    4.    (progn
    5.      (setvar "PEDITACCEPT" 1)
    6.      (command "_.pedit" "_M" st "" "_J" "20" "" );_join and fill the gaps
    7.      (setvar "PEDITACCEPT" ope)
    8.    )
    9. )
    10. ;_
    11. (setq q (getvar 'qaflags))
    12.            (setvar 'qaflags 1)
    13.            (command "_.explode" entlast "");_explode the converted polyline
    14.            (setvar 'qaflags q)
    15. (setq        i 0
    16. z 0
    17. )
    18. ;_find intesection and mark them
    19. (while (< i (- (sslength st) 1))
    20.    (while (< z (- (sslength st) 1))
    21.      (setq mx (ssname st i))
    22.      (setq my (ssname st (+ z 1)))
    23.      (if (setq cen (findInters mx my))
    24. (progn
    25.   (command "Circle" cen 8 "")
    26. )
    27.      )
    28.      (setq z (1+ z))
    29.    ) ;_while
    30.    (setq i (1+ i))
    31.    (setq z 0)
    32. )
    33. )
    34. (defun findInters (entA entB)
    35. (setq 1a (cdr (assoc 10 (entget entA))))
    36. (setq 1b (cdr (assoc 11 (entget entA))))
    37. (setq 2a (cdr (assoc 10 (entget entB))))
    38. (setq 2b (cdr (assoc 11 (entget entB))))
    39. (setq in (inters 1a 1b 2a 2b))
    40. )
    41. (defun c:jp (/ ope ss)
    42. (setq ope (getvar "PEDITACCEPT"))
    43. (if (setq ss (ssget '((0 . "ARC,*POLYLINE,LINE"))))
    44.    (progn
    45.      (setvar "PEDITACCEPT" 1)
    46.      (command "_.pedit" "_M" ss "" "_J" "" "")
    47.    )
    48. )
    49. (setvar "PEDITACCEPT" ope)
    50. (princ)
    51. )

     
    谢谢
    谢伊
    005617gwmmc33s4cw4w5vc.jpg
  • 回复

    使用道具 举报

    63

    主题

    6297

    帖子

    6283

    银币

    后起之秀

    Rank: 20Rank: 20Rank: 20Rank: 20

    铜币
    358
    发表于 2022-7-6 00:00:30 | 显示全部楼层
    至少你应该感谢在这篇文章中试图在同一问题上帮助你的先生们
    回复

    使用道具 举报

    35

    主题

    2471

    帖子

    2447

    银币

    初露锋芒

    Rank: 3Rank: 3Rank: 3

    铜币
    174
    发表于 2022-7-6 00:03:35 | 显示全部楼层
    Samifox,请注意您如何调用ENTLAST(是一个函数):
    1. (command "_.explode" [color=red]([/color]entlast[color=red])[/color] "")
    回复

    使用道具 举报

    pBe

    32

    主题

    2722

    帖子

    2666

    银币

    后起之秀

    Rank: 20Rank: 20Rank: 20Rank: 20

    铜币
    211
    发表于 2022-7-6 00:06:52 | 显示全部楼层
    是我的眼睛欺骗了我,还是“爆炸”的线条没有在你贴的pix上对齐?这真的是你的意图吗?
    回复

    使用道具 举报

    5

    主题

    1334

    帖子

    1410

    银币

    限制会员

    铜币
    -20
    发表于 2022-7-6 00:10:47 | 显示全部楼层
    谢,如果我理解正确的话,这就是你需要的。。。
     
    1. (defun plintav ( / intersobj1obj2 LM:Unique AT:GetVertices _reml member-fuzz add_vtx
    2.                   ss sslpl sshpl i ent n ent1 ss-ent1 k ent2 intpts intptsall pl plpts restintpts par )
    3. (vl-load-com)
    4. (defun intersobj1obj2 ( obj1 obj2 / coords pt ptlst )
    5.    (if (eq (type obj1) 'ENAME) (setq obj1 (vlax-ename->vla-object obj1)))
    6.    (if (eq (type obj2) 'ENAME) (setq obj2 (vlax-ename->vla-object obj2)))
    7.    (setq coords (vl-catch-all-apply 'vlax-safearray->list (list (vl-catch-all-apply 'vlax-variant-value (list (vla-intersectwith obj1 obj2 AcExtendNone))))))
    8.    (if (vl-catch-all-error-p coords)
    9.      (setq ptlst nil)
    10.      (repeat (/ (length coords) 3)
    11.        (setq pt (list (car coords) (cadr coords) (caddr coords)))
    12.        (setq ptlst (cons pt ptlst))
    13.        (setq coords (cdddr coords))
    14.      )
    15.    )
    16.    ptlst
    17. )  
    18. (defun LM:Unique ( lst )
    19.    (if lst (cons (car lst) (LM:Unique (vl-remove (car lst) (cdr lst)))))
    20. )
    21. (defun AT:GetVertices ( e / p l )
    22.    (LM:Unique
    23.      (if e
    24.        (if (eq (setq p (vlax-curve-getEndParam e)) (fix p))
    25.          (repeat (setq p (1+ (fix p)))
    26.            (setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l))
    27.          )
    28.          (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e))
    29.        )
    30.      )
    31.    )
    32. )
    33. (defun _reml ( l1 l2 / a n ls )
    34.    (while
    35.      (setq n nil
    36.            a (car l2)
    37.      )
    38.      (while (and l1 (null n))
    39.        (if (equal a (car l1) 1e-
    40.          (setq l1 (cdr l1)
    41.                n t
    42.          )
    43.          (setq ls (append ls (list (car l1)))
    44.                l1 (cdr l1)
    45.          )
    46.        )
    47.      )
    48.      (setq l2 (cdr l2))
    49.    )
    50.    (append ls l1)
    51. )
    52. (defun member-fuzz ( expr lst fuzz )
    53.    (while (and lst (not (equal (car lst) expr fuzz)))
    54.      (setq lst (cdr lst))
    55.    )
    56.    lst
    57. )
    58. (defun add_vtx ( obj add_pt ent_name / bulg )
    59.      (vla-addVertex
    60.          obj
    61.          (1+ (fix add_pt))
    62.          (vlax-make-variant
    63.              (vlax-safearray-fill
    64.                  (vlax-make-safearray vlax-vbdouble (cons 0 1))
    65.                      (list
    66.                          (car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
    67.                          (cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
    68.                      )
    69.              )
    70.          )
    71.      )
    72.      (setq bulg (vla-GetBulge obj (fix add_pt)))
    73.      (vla-SetBulge obj
    74.          (fix add_pt)
    75.          (/
    76.              (sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
    77.              (cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
    78.          )
    79.      )
    80.      (vla-SetBulge obj
    81.          (1+ (fix add_pt))
    82.          (/
    83.              (sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
    84.              (cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
    85.          )
    86.      )
    87.      (vla-update obj)
    88. )
    89. (setq ss (ssget "_I" '((0 . "*POLYLINE") (-4 . "<and") (-4 . "<not") (-4 . "&=") (70 .  (-4 . "not>") (-4 . "<") (70 . 130) (-4 . "and>"))))
    90. (setq sslpl (ssadd) sshpl (ssadd))
    91. (setq i -1)
    92. (while (setq ent (ssname ss (setq i (1+ i))))
    93.    (if (eq (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
    94.      (progn
    95.        (entupd ent)
    96.        (vla-update (vlax-ename->vla-object ent))
    97.        (ssadd ent sslpl)
    98.      )
    99.    )
    100.    (if (eq (cdr (assoc 0 (entget ent))) "POLYLINE")
    101.      (ssadd ent sshpl)
    102.    )
    103. )
    104. (setq i -1)
    105. (while (setq ent (ssname sshpl (setq i (1+ i))))
    106.    (command "_.convertpoly" "l" ent "")
    107.    (entupd ent)
    108.    (vla-update (vlax-ename->vla-object ent))
    109.    (ssadd ent sslpl)
    110. )
    111. (repeat (setq n (sslength ss))
    112.    (setq ent1 (ssname ss (setq n (1- n))))
    113.    (setq ss-ent1 (ssdel ent1 ss))
    114.    (repeat (setq k (sslength ss-ent1))
    115.      (setq ent2 (ssname ss-ent1 (setq k (1- k))))
    116.      (setq intpts (intersobj1obj2 ent1 ent2))
    117.      (setq intptsall (append intpts intptsall))
    118.    )
    119. )
    120. (setq i -1)
    121. (while (setq pl (ssname sslpl (setq i (1+ i))))
    122.    (setq plpts (AT:GetVertices pl))
    123.    (setq restintpts (_reml intptsall plpts))
    124.    (foreach pt restintpts
    125.      (if
    126.        (and
    127.          (not (member-fuzz pt plpts 1e-6))
    128.          (setq par (vlax-curve-getparamatpoint pl pt))
    129.        )
    130.        (add_vtx (vlax-ename->vla-object pl) par pl)        
    131.      )
    132.    )
    133. )
    134. (setq i -1)
    135. (while (setq ent (ssname sshpl (setq i (1+ i))))
    136.    (command "_.convertpoly" "h" ent "")
    137. )
    138. (princ)
    139. )
    140. (defun c:test (/ pea qaf ss sspl ssli i ent)
    141. (setq pea (getvar "PEDITACCEPT"))
    142. (setq qaf (getvar "QAFLAGS"))
    143. (if (setq ss (ssget '((0 . "ARC,*POLYLINE,LINE"))))
    144.    (progn
    145.      (setq sspl (ssadd))
    146.      (setq ssli (ssadd))
    147.      (setq i -1)
    148.      (while (setq ent (ssname ss (setq i (1+ i))))
    149.        (if (wcmatch (cdr (assoc 0 (entget ent))) "*POLYLINE")
    150.          (ssadd ent sspl)
    151.          (progn
    152.            (setvar "PEDITACCEPT" 1)
    153.            (command "_.pedit" ent "")
    154.            (ssadd (entlast) ssli)
    155.          )
    156.        )
    157.      )
    158.    )
    159. )
    160. (sssetfirst nil (acet-ss-union (list ssli sspl)))
    161. (plintav)
    162. (setvar "QAFLAGS" 1)
    163. (command "_.explode")
    164. (setvar "QAFLAGS" qaf)
    165. (setvar "PEDITACCEPT" pea)
    166. (princ)
    167. )

     
    它是什么?
     
    谢谢
    谢伊
    回复

    使用道具 举报

    pBe

    32

    主题

    2722

    帖子

    2666

    银币

    后起之秀

    Rank: 20Rank: 20Rank: 20Rank: 20

    铜币
    211
    发表于 2022-7-6 00:12:35 | 显示全部楼层
    回复

    使用道具 举报

    pBe

    32

    主题

    2722

    帖子

    2666

    银币

    后起之秀

    Rank: 20Rank: 20Rank: 20Rank: 20

    铜币
    211
    发表于 2022-7-6 00:20:38 | 显示全部楼层
    "PEDITACCEPT" for the code to work on lines as well, i'm just saying.
     
    BTW: Suppresses display of the Object Selected Is Not a Polyline prompt in PEDIT
     
    @samifox
    What is the intent of the program again?
    回复

    使用道具 举报

    218

    主题

    699

    帖子

    483

    银币

    顶梁支柱

    Rank: 50Rank: 50

    铜币
    1090
    发表于 2022-7-6 00:24:30 | 显示全部楼层
     
    yes...i totaly forgot
     
    and its not the same issue , its look like the same images
    回复

    使用道具 举报

    5

    主题

    1334

    帖子

    1410

    银币

    限制会员

    铜币
    -20
    发表于 2022-7-6 00:26:07 | 显示全部楼层
     
    Yes, pBe you're correct... I've used setting of 1 and didn't saw it won't work... Code updated...
     
    Thanks, pBe...
    回复

    使用道具 举报

    218

    主题

    699

    帖子

    483

    银币

    顶梁支柱

    Rank: 50Rank: 50

    铜币
    1090
    发表于 2022-7-6 00:30:23 | 显示全部楼层
     
    im using 2010
     
     
    yes..on the left is before, and on the right is the desired result (the offset is only to clear the point, they should share the same points)
    回复

    使用道具 举报

    发表回复

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    • 微信公众平台

    • 扫描访问手机版

    • 点击图片下载手机App

    QQ|关于我们|小黑屋|乐筑天下 繁体中文

    GMT+8, 2025-3-10 21:13 , Processed in 0.482990 second(s), 75 queries .

    © 2020-2025 乐筑天下

    联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表