乐筑天下

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

[编程交流] 制作连续的pline

[复制链接]

55

主题

243

帖子

188

银币

后起之秀

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

铜币
275
发表于 2022-7-6 10:47:38 | 显示全部楼层 |阅读模式
我的测试代码生成了一系列PLINE。
我想知道的是,在while循环中,如何将每个单独的pline放置到一个实体集中?
 
因此,如果有三个pline实体(e1 e2 e3),那么我可以
使用:
(命令“_.PEDIT”e1”连接“e2 e3”)
将这三条线变成一条连续的线。
 
 
 
  1. (defun c:testcode (/ pt1 pt2 e1)
  2. (setq pt1 (getpoint "\nFirst point: "))
  3. (while pt1
  4.    (setq pt2 (getpoint pt1 "\nNext point: "))
  5.    (if pt2
  6.      (progn
  7.        (command "_pline" pt1 pt2 "")
  8. (setq e1(entlast))
  9.        (setq pt1 pt2)
  10.      );progn
  11.      (setq pt1 nil)
  12.    );if
  13.    
  14.    );while
  15. );defun
回复

使用道具 举报

4

主题

57

帖子

53

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 10:55:41 | 显示全部楼层
这是我不久前做的一部分。它从用户那里获取点,并将它们组合成一条多段线。此外,它还会计算您移动时的距离。我需要这样才能在整个代码的另一部分中划分分段。我希望我不会因为命令调用而受到太多惩罚,这是我在2007年写的。
 
  1. (defun WR:GetPoints (/ FirstPoint NextPoint xaaa xbbb yaaa ybbb xdist ydist)
  2. (setvar "osmode" 161)
  3. (setvar "orthomode" 0)
  4. (setq sspolyline nil CalculatedDistance nil)
  5. (setq FirstPoint (getpoint "\nPick first point of polyline: "))(terpri)
  6. (setq NextPoint (getpoint FirstPoint "\nPick next point of polyline: "))(terpri)
  7. (setq LastPoint FirstPoint)
  8. (setq xaaa (car LastPoint))
  9. (setq yaaa (cadr LastPoint))
  10. (setq xbbb (car NextPoint))
  11. (setq ybbb (cadr NextPoint))
  12. (if (< xaaa xbbb)
  13.    (setq xdist (- xbbb xaaa))
  14.    (setq xdist (- xaaa xbbb))
  15. )
  16. (if (< yaaa ybbb)
  17.    (setq ydist (- ybbb yaaa))
  18.    (setq ydist (- yaaa ybbb))
  19. )
  20. (setq CalculatedDistance (sqrt (+ (* xdist xdist) (* ydist ydist))))
  21. (command "layer" "M" "E-Temp1" "c" "30" "E-Temp1" "P" "N" "E-Temp1" "S" "E-Temp1" "")
  22. (command "pline" LastPoint "w" "1" "1" NextPoint "")
  23. (setq poly1 (entlast))
  24. (setq ssPolyline (ssadd))
  25. (ssadd poly1 ssPolyline)
  26. (setq polylinePointList (cons LastPoint polylinePointList))
  27. (setq LastPoint NextPoint)
  28. (while
  29.    (setq NextPoint (getpoint LastPoint "\nPick next point of polyline or press <Enter> to end command:"))
  30.    (terpri)
  31.    (setq xaaa (car LastPoint))
  32.    (setq yaaa (cadr LastPoint))
  33.    (setq xbbb (car NextPoint))
  34.    (setq ybbb (cadr NextPoint))
  35.    (if (< xaaa xbbb)
  36.      (setq xdist (- xbbb xaaa))
  37.      (setq xdist (- xaaa xbbb))
  38.    )
  39.    (if (< yaaa ybbb)
  40.      (setq ydist (- ybbb yaaa))
  41.      (setq ydist (- yaaa ybbb))
  42.    )
  43.    (setq AddToCalculatedDistance (sqrt (+ (* xdist xdist) (* ydist ydist))))
  44.    (setq CalculatedDistance (+ CalculatedDistance AddToCalculatedDistance))
  45.    (command "pline" LastPoint NextPoint "")
  46.    (setq polynew (entlast))
  47.    (command "pedit" "l" "j" polynew ssPolyline "" "")
  48.    (setq poly1 (entlast))
  49.    (ssadd poly1 ssPolyline)
  50.    (setq polylinePointList (cons LastPoint polylinePointList))
  51.    (setq LastPoint NextPoint)
  52. );end while
  53. (princ)
  54. );end WR:GetPoints

 
那里有一些标志,可以为你指明正确的方向。
回复

使用道具 举报

13

主题

146

帖子

136

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
62
发表于 2022-7-6 11:00:40 | 显示全部楼层
几个月来,我一直在使用lpseifert的这个优秀的小程序。如果选定的任何直线不是多段线,则在连接之前将对其进行转换。调整模糊距离以适应。
 
  1. ;
  2. ; By lpseifert on CADTutor
  3. ; http://www.cadtutor.net/forum/showthread.php?t=41420
  4. ;
  5. ; Changed FUZZ to 0.00 and a coupla minor comment modifications
  6. ;
  7. ; WHAT IS DOES -------------------------------------------|
  8. ;                                                         |
  9. ;                                                        \|/
  10. ;                                                         V
  11. (defun c:pj (/ ssj)                              ;defines the function and declares local variables
  12. (setq pa (getvar "peditaccept"))               ;stores the existing peditaccept variable setting
  13. (setvar "peditaccept" 1)                       ;sets the peditaccept variable to 1, which suppresses the prompts for
  14.                                                 ;non-plines, and automatically converts them to plines
  15.    (setq ssj (ssget ))                          ;gets and stores your selection
  16.    (command "PEDIT" "M" ssj ""  "J" "0.00" "")  ;does PEDIT stuff to what you selected (JOIN with fuzz = 0.00)
  17. ;(command "PEDIT" "m" ssj "" "j" "0.00" "s" "")  ;<-(use this line if you want to turn it into a spline after joining)
  18. (setvar "peditaccept" pa)                      ;restores peditaccept to what it was
  19. (princ)                                          ;clean exit
  20. )                                                ;the end
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:03:06 | 显示全部楼层
这就是你想要的吗?
 
  1. (command "_.pline")
  2. (while (= 1 (logand 1 (getvar 'CMDACTIVE)))
  3. (command pause)
  4. )
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 11:06:13 | 显示全部楼层
哎呀,没想到李发了帖子。
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 11:15:17 | 显示全部楼层
谢谢大家的回复-Chlucfeng最接近我想要做的。对不起,我的代码和解释有点简短。
 
下面是我要做的:
1) 绘制pline
2) 断开pline
3) 在打断中插入特征线符号
4) 修剪线条
5) 继续,直到按下enter键(使用while循环)
这在这里很有效。。。
6) 问题部分。。。。。我想做的是使用“PEDIT”“JOIN”。。。电子不停车收费系统
 
我的问题是,我无法使用“entlast”识别断裂pline的两半,然后使用Chlucfeng在代码中建议的“ssadd”。
也许你们中有人知道一个更好的方法,把它变成一个连续的pline?
谢谢你的回复
 
 
 
  1. (defun c:Test (/ pt)
  2. (if (setq pt (getpoint "\nSpecify first point: "))
  3.    (progn
  4.      (command "_.pline" "_non" pt)
  5.      (while (> (getvar 'cmdactive) 0)
  6.        (princ "\nSpecify next point: ")
  7.        (command PAUSE)
  8.      )
  9.    )
  10. )
  11. (princ)
  12. )

BrkLine2.dwg
回复

使用道具 举报

55

主题

243

帖子

188

银币

后起之秀

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

铜币
275
发表于 2022-7-6 11:15:52 | 显示全部楼层
您存储了原始实体,一旦原始实体被破坏,您可以访问新实体(将是原始的和新的-使用entlast获取)。
 
下面是一个丑陋的例子:
 
  1. (defun c:bl2(/ pt1 pt2  pt3 pt4 pt5 pt6 pt7 pt8   x1    x2     ss
  2.        lk flag  sca   size    ds     os ptbrk ang
  3.        e1 e2 e3 e4 SB_pickpoint   SB_next  SB_ent   SB_proceed
  4.        SB_next SB_distance SB_entlist SB_closest_point SB_closest_ent SB_newent
  5. )
  6. (setq sel1 nil)      
  7. (setq pt1 (getpoint "\nSpecify first point for breakline: ")
  8.       pt2 (getpoint pt1 "\nSpecify second point for breakline: ")
  9.       BrkScale 1.0;temp scale to 1
  10. );setq
  11. (command "Pline" pt1 pt2 "")
  12. (setq SB_ent (entlast)
  13.       e2 (entlast)
  14.       SB_pickpoint T
  15.       SB_next nil
  16.       SB_entlist (list SB_ent)
  17. );setq
  18. (while
  19. (setvar "osmode" 512)
  20. (setq SB_pickpoint (getpoint (if SB_next
  21.          "\nSpecify next breakpoint: "
  22.          "\nSpecify breakpoint: "
  23.          );if
  24. ))
  25. (setq SB_proceed T
  26.        SB_next T
  27.        SB_distance 1.0e+012
  28. );setq
  29. ;;; Find the closest element of all the sub-elements ;
  30. (foreach SB_nth SB_entlist
  31. (setq SB_obj (vlax-ename->vla-object SB_nth)
  32.        SB_foundpoint (vlax-curve-getClosestPointTo SB_obj
  33.        SB_pickpoint nil)
  34. );setq
  35. (if (< (setq SB_temp (distance SB_pickpoint SB_foundpoint)) SB_distance)
  36.      (setq SB_distance SB_temp
  37.            SB_closest_ent SB_nth
  38.            SB_closest_point SB_foundpoint
  39. );setq
  40. );if
  41. );foreach
  42. (command "_break" SB_closest_ent SB_closest_point SB_closest_point)
  43. ;;; add the newly created element to the sub-elements ;
  44. (setq SB_newent (entlast))
  45. ;;;  (setq sel1 (ssadd SB_newent e2))
  46.   (if (not (member SB_newent SB_entlist))
  47. (setq SB_entlist (cons SB_newent SB_entlist))
  48. );if
  49. (command ".INSERT"
  50.    "BRKLINE2"
  51.    SB_closest_point
  52.    BrkScale;scale
  53.    ""
  54.    pt1
  55.    pt2 ;angle
  56.    )
  57. (command ".EXPLODE" "LAST");explode block to pline
  58. (setq e3(entlast))
  59. ;;; (setq sel2 (ssadd sel1 e3))
  60. (setq  
  61.        pt4  (polar SB_closest_point   (angle pt1 pt2) (* 1.5 BrkScale))
  62.        pt4a (polar pt4 (*(angle pt1 pt2)(* 0.5 pi))(* 1.5 BrkScale))
  63.        pt4b (polar pt4 (*(angle pt1 pt2)0.5 pi)(* 1.5 BrkScale))
  64.        pt5 (polar SB_closest_point (-(angle Pt1 Pt2)(* 1.25 pi))(* 1.5 BrkScale))
  65.        pt6 (polar SB_closest_point (+(angle Pt1 Pt2)(* 1.25 pi))(* 1.5 BrkScale))
  66.        pt7 (polar SB_closest_point (-(angle Pt2 Pt1)(* 1.25 pi))(* 1.5 BrkScale))
  67.        pt8 (polar SB_closest_point (+(angle Pt2 Pt1)(* 1.25 pi))(* 1.5 BrkScale))
  68. );setq
  69. (setvar "OSMODE" 0)
  70. (command "trim" e3 "" "fence" pt6  pt5 "" "")
  71. (command "trim" e3 "" "fence" pt7  pt8 "" "")
  72. ;;; (command "_.PEDIT" e3 "JOIN"  e1 "" "")
  73. );while
  74. (princ)
  75. );defun

 
它将在两个拾取的点之间绘制一条线,然后在中点处打断并连接成多段线。
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 11:24:28 | 显示全部楼层
嘿,谢谢你的快速回复!是的,这就是我想要做的。
我用了你的台词:
(setq ss(ssadd e1(ssadd(entlast)))
它仅适用于一个打断,但插入另一个打断符号时有效
它挂在线路上:
(setq SB\u foundpoint(vlax curve getclosestpoint to SB\u obj)
不知道为什么?
回复

使用道具 举报

55

主题

243

帖子

188

银币

后起之秀

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

铜币
275
发表于 2022-7-6 11:27:04 | 显示全部楼层
因为vlax curve getClosestPointTo有两个要求。
[列表=1]
  • 对象(enameor vla对象)

  • [/列表]
  • 回复

    使用道具 举报

    54

    主题

    3755

    帖子

    3583

    银币

    后起之秀

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

    铜币
    438
    发表于 2022-7-6 11:29:28 | 显示全部楼层
    插入块时,可以在块名称之前使用星号“*”自动分解块,因此无需使用分解命令。
     
    1. (defun c:Test (/ p1 p2 e1 mp ss)
    2. (if (and (setq p1 (getpoint "\nSpecify first point: "))
    3.           (setq p2 (getpoint p1 "\nSpecify next point: "))
    4.      )
    5.    (progn
    6.      (command "_.line" "_non" p1 "_non" p2 "")
    7.      (setq e1 (entlast)
    8.            mp (mapcar '(lambda (a b) (/ (+ a b) 2.)) p1 p2)
    9.      )
    10.      (command "_.break" e1 "_non" mp "_non" mp)
    11.      (setq ss (ssadd e1 (ssadd (entlast))))
    12.      (if (eq (getvar 'peditaccept) 1)
    13.        (command "_.pedit" "_m" ss "" "_j" "" "")
    14.        (command "_.pedit" "_m" ss "" "_y" "_j" "" "")
    15.      )
    16.    )
    17. )
    18. (princ)
    19. )

     
    我阅读你的代码也是为了尝试让多段线连接起来。打断完成并连接后,您是否应该从最后一个打断的位置继续多段线?
     
    Chuck(chlucfeng)
    回复

    使用道具 举报

    发表回复

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

    本版积分规则

    • 微信公众平台

    • 扫描访问手机版

    • 点击图片下载手机App

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

    GMT+8, 2025-3-6 16:54 , Processed in 0.394618 second(s), 72 queries .

    © 2020-2025 乐筑天下

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