Small Fish 发表于 2022-7-6 10:47:38

制作连续的pline

我的测试代码生成了一系列PLINE。
我想知道的是,在while循环中,如何将每个单独的pline放置到一个实体集中?
 
因此,如果有三个pline实体(e1 e2 e3),那么我可以
使用:
(命令“_.PEDIT”e1”连接“e2 e3”)
将这三条线变成一条连续的线。
 
 
 

(defun c:testcode (/ pt1 pt2 e1)
(setq pt1 (getpoint "\nFirst point: "))
(while pt1
   (setq pt2 (getpoint pt1 "\nNext point: "))
   (if pt2
   (progn
       (command "_pline" pt1 pt2 "")
(setq e1(entlast))
       (setq pt1 pt2)
   );progn
   (setq pt1 nil)
   );if
   
   );while
);defun

CHLUCFENG 发表于 2022-7-6 10:55:41

这是我不久前做的一部分。它从用户那里获取点,并将它们组合成一条多段线。此外,它还会计算您移动时的距离。我需要这样才能在整个代码的另一部分中划分分段。我希望我不会因为命令调用而受到太多惩罚,这是我在2007年写的。
 

(defun WR:GetPoints (/ FirstPoint NextPoint xaaa xbbb yaaa ybbb xdist ydist)
(setvar "osmode" 161)
(setvar "orthomode" 0)
(setq sspolyline nil CalculatedDistance nil)
(setq FirstPoint (getpoint "\nPick first point of polyline: "))(terpri)
(setq NextPoint (getpoint FirstPoint "\nPick next point of polyline: "))(terpri)
(setq LastPoint FirstPoint)
(setq xaaa (car LastPoint))
(setq yaaa (cadr LastPoint))
(setq xbbb (car NextPoint))
(setq ybbb (cadr NextPoint))
(if (< xaaa xbbb)
   (setq xdist (- xbbb xaaa))
   (setq xdist (- xaaa xbbb))
)
(if (< yaaa ybbb)
   (setq ydist (- ybbb yaaa))
   (setq ydist (- yaaa ybbb))
)
(setq CalculatedDistance (sqrt (+ (* xdist xdist) (* ydist ydist))))
(command "layer" "M" "E-Temp1" "c" "30" "E-Temp1" "P" "N" "E-Temp1" "S" "E-Temp1" "")
(command "pline" LastPoint "w" "1" "1" NextPoint "")
(setq poly1 (entlast))
(setq ssPolyline (ssadd))
(ssadd poly1 ssPolyline)
(setq polylinePointList (cons LastPoint polylinePointList))
(setq LastPoint NextPoint)
(while
   (setq NextPoint (getpoint LastPoint "\nPick next point of polyline or press <Enter> to end command:"))
   (terpri)
   (setq xaaa (car LastPoint))
   (setq yaaa (cadr LastPoint))
   (setq xbbb (car NextPoint))
   (setq ybbb (cadr NextPoint))
   (if (< xaaa xbbb)
   (setq xdist (- xbbb xaaa))
   (setq xdist (- xaaa xbbb))
   )
   (if (< yaaa ybbb)
   (setq ydist (- ybbb yaaa))
   (setq ydist (- yaaa ybbb))
   )
   (setq AddToCalculatedDistance (sqrt (+ (* xdist xdist) (* ydist ydist))))
   (setq CalculatedDistance (+ CalculatedDistance AddToCalculatedDistance))
   (command "pline" LastPoint NextPoint "")
   (setq polynew (entlast))
   (command "pedit" "l" "j" polynew ssPolyline "" "")
   (setq poly1 (entlast))
   (ssadd poly1 ssPolyline)
   (setq polylinePointList (cons LastPoint polylinePointList))
   (setq LastPoint NextPoint)
);end while
(princ)
);end WR:GetPoints

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

StevJ 发表于 2022-7-6 11:00:40

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

Lee Mac 发表于 2022-7-6 11:03:06

这就是你想要的吗?
 

(command "_.pline")
(while (= 1 (logand 1 (getvar 'CMDACTIVE)))
(command pause)
)

alanjt 发表于 2022-7-6 11:06:13

哎呀,没想到李发了帖子。

alanjt 发表于 2022-7-6 11:15:17

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

Small Fish 发表于 2022-7-6 11:15:52

您存储了原始实体,一旦原始实体被破坏,您可以访问新实体(将是原始的和新的-使用entlast获取)。
 
下面是一个丑陋的例子:
 

(defun c:bl2(/ pt1 pt2pt3 pt4 pt5 pt6 pt7 pt8   x1    x2   ss
       lk flagsca   size    ds   os ptbrk ang
       e1 e2 e3 e4 SB_pickpoint   SB_nextSB_ent   SB_proceed
       SB_next SB_distance SB_entlist SB_closest_point SB_closest_ent SB_newent
)
(setq sel1 nil)      
(setq pt1 (getpoint "\nSpecify first point for breakline: ")
      pt2 (getpoint pt1 "\nSpecify second point for breakline: ")
      BrkScale 1.0;temp scale to 1
);setq
(command "Pline" pt1 pt2 "")
(setq SB_ent (entlast)
      e2 (entlast)
      SB_pickpoint T
      SB_next nil
      SB_entlist (list SB_ent)
);setq
(while
(setvar "osmode" 512)
(setq SB_pickpoint (getpoint (if SB_next
         "\nSpecify next breakpoint: "
         "\nSpecify breakpoint: "
         );if
))
(setq SB_proceed T
       SB_next T
       SB_distance 1.0e+012
);setq

;;; Find the closest element of all the sub-elements ;
(foreach SB_nth SB_entlist
(setq SB_obj (vlax-ename->vla-object SB_nth)
       SB_foundpoint (vlax-curve-getClosestPointTo SB_obj
       SB_pickpoint nil)
);setq
(if (< (setq SB_temp (distance SB_pickpoint SB_foundpoint)) SB_distance)
   (setq SB_distance SB_temp
         SB_closest_ent SB_nth
         SB_closest_point SB_foundpoint
);setq
);if
);foreach
(command "_break" SB_closest_ent SB_closest_point SB_closest_point)
;;; add the newly created element to the sub-elements ;
(setq SB_newent (entlast))
;;;(setq sel1 (ssadd SB_newent e2))
(if (not (member SB_newent SB_entlist))
(setq SB_entlist (cons SB_newent SB_entlist))
);if
(command ".INSERT"
   "BRKLINE2"
   SB_closest_point
   BrkScale;scale
   ""
   pt1
   pt2 ;angle
   )
(command ".EXPLODE" "LAST");explode block to pline
(setq e3(entlast))
;;; (setq sel2 (ssadd sel1 e3))
(setq
       pt4(polar SB_closest_point   (angle pt1 pt2) (* 1.5 BrkScale))
       pt4a (polar pt4 (*(angle pt1 pt2)(* 0.5 pi))(* 1.5 BrkScale))
       pt4b (polar pt4 (*(angle pt1 pt2)0.5 pi)(* 1.5 BrkScale))
       pt5 (polar SB_closest_point (-(angle Pt1 Pt2)(* 1.25 pi))(* 1.5 BrkScale))
       pt6 (polar SB_closest_point (+(angle Pt1 Pt2)(* 1.25 pi))(* 1.5 BrkScale))
       pt7 (polar SB_closest_point (-(angle Pt2 Pt1)(* 1.25 pi))(* 1.5 BrkScale))
       pt8 (polar SB_closest_point (+(angle Pt2 Pt1)(* 1.25 pi))(* 1.5 BrkScale))
);setq
(setvar "OSMODE" 0)
(command "trim" e3 "" "fence" pt6pt5 "" "")
(command "trim" e3 "" "fence" pt7pt8 "" "")
;;; (command "_.PEDIT" e3 "JOIN"e1 "" "")
);while
(princ)
);defun

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

alanjt 发表于 2022-7-6 11:24:28

嘿,谢谢你的快速回复!是的,这就是我想要做的。
我用了你的台词:
(setq ss(ssadd e1(ssadd(entlast)))
它仅适用于一个打断,但插入另一个打断符号时有效
它挂在线路上:
(setq SB\u foundpoint(vlax curve getclosestpoint to SB\u obj)
不知道为什么?

Small Fish 发表于 2022-7-6 11:27:04

因为vlax curve getClosestPointTo有两个要求。
[列表=1]
[*]对象(enameor vla对象)
[*]点
[/列表]

alanjt 发表于 2022-7-6 11:29:28

插入块时,可以在块名称之前使用星号“*”自动分解块,因此无需使用分解命令。
 
(defun c:Test (/ p1 p2 e1 mp ss)
(if (and (setq p1 (getpoint "\nSpecify first point: "))
          (setq p2 (getpoint p1 "\nSpecify next point: "))
   )
   (progn
   (command "_.line" "_non" p1 "_non" p2 "")
   (setq e1 (entlast)
         mp (mapcar '(lambda (a b) (/ (+ a b) 2.)) p1 p2)
   )
   (command "_.break" e1 "_non" mp "_non" mp)
   (setq ss (ssadd e1 (ssadd (entlast))))
   (if (eq (getvar 'peditaccept) 1)
       (command "_.pedit" "_m" ss "" "_j" "" "")
       (command "_.pedit" "_m" ss "" "_y" "_j" "" "")
   )
   )
)
(princ)
)
 
我阅读你的代码也是为了尝试让多段线连接起来。打断完成并连接后,您是否应该从最后一个打断的位置继续多段线?
 
Chuck(chlucfeng)
页: [1] 2
查看完整版本: 制作连续的pline