Mohamed Haytham Posted 21 hours ago Posted 21 hours ago Hi, It would be great if you can help me with the following. I have multiple polylines where they have different widths (Originally creating by fillet a line with width 1 and a line with width 2). Is there a way to split them to the original state where the are 2 lines and each has it's actual widths? I am attaching a file with the issue, and the expected solution, but this is only file with 2 polylines as an example, but this issue is happening with a file having more than 1000 polyline. Break Polyline at different depth.dwg Quote
Nikon Posted 18 hours ago Posted 18 hours ago Try this code ;; author ::Jaifl:: ;; divides polylines into separate segments, preserving thickness, color, layer (defun c:SplitPlSeg ( / ss i ent elist points widths bulges n j p1 p2 w1 w2 bulge color layer ltype lweight transp) (setq ss (ssget '((0 . "LWPOLYLINE")))) (if ss (progn (setq i 0) (while (< i (sslength ss)) (setq ent (ssname ss i)) (setq elist (entget ent)) (setq color (assoc 62 elist)) (setq layer (assoc 8 elist)) (setq ltype (assoc 6 elist)) (setq lweight (assoc 370 elist)) (setq transp (assoc 440 elist)) (setq points '() widths '() bulges '()) (foreach x elist (cond ((= (car x) 10) (setq points (append points (list (cdr x))))) ((= (car x) 40) (setq widths (append widths (list (cdr x))))) ((= (car x) 41) (setq widths (append widths (list (cdr x))))) ((= (car x) 42) (setq bulges (append bulges (list (cdr x))))) ) ) (setq n (length points)) (setq j 0) (while (< j (1- n)) (setq p1 (nth j points)) (setq p2 (nth (+ j 1) points)) (setq w1 (nth (* j 2) widths)) ; Start width (setq w2 (nth (1+ (* j 2)) widths)) ; End width (setq bulge (if (< j (length bulges)) (nth j bulges) 0.0)) (setq newent (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") layer ) (if color (list color) '()) (if ltype (list ltype) '()) (if lweight (list lweight) '()) (if transp (list transp) '()) (list (cons 100 "AcDbPolyline") (cons 90 2) (cons 70 0) (list 10 (car p1) (cadr p1)) (cons 40 w1) (cons 41 w2) (cons 42 bulge) (list 10 (car p2) (cadr p2)) (cons 40 w2) (cons 41 w2) ) ) ) (entmake newent) (setq j (1+ j)) ) (entdel ent) ; delete the original polyline (setq i (1+ i)) ) ) (princ "There are no selected polylines.") ) (princ) ) Quote
ronjonp Posted 16 hours ago Posted 16 hours ago (edited) Another for fun: (defun c:foo (/ a b el l s) ;; RJP » 2025-07-21 ;; Creates separate polyline segments preserving widths etc.. (cond ((setq s (ssget '((0 . "LWPOLYLINE")))) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq el (entget e)) (setq a (append (reverse (member '(100 . "AcDbPolyline") (reverse el))) '((90 . 2)))) (setq b (vl-remove-if-not '(lambda (x) (member (car x) '(10 40 41 42))) el)) (while (cddddr b) (setq l nil) (setq l (list (car b) (cadr b) (caddr b) (cadddr b))) (setq b (cddddr b)) (entmakex (append a (append l (list (car b) (cadr b) (caddr b) (cadddr b))))) ) (entdel e) ) ) ) (princ) ) Edited 16 hours ago by ronjonp 1 1 Quote
marko_ribar Posted 6 hours ago Posted 6 hours ago (edited) I might be wrong, but can this be achieved just by using EXPLODE command? [EDIT : I see it now... EXPLODE command converts segments into LINE and ARC entities, so widths are lost...] Edited 6 hours ago by marko_ribar Quote
Emmanuel Delay Posted 6 hours ago Posted 6 hours ago 13 minutes ago, marko_ribar said: I might be wrong, but can this be achieved just by using EXPLODE command? Exploding polylines makes lines. Lines have no width. The question is to "explode", but keep all edges as polyline with the original width Quote
Tsuky Posted 3 hours ago Posted 3 hours ago Yet another... (defun c:break_lw ( / js i ent dxf_obj dxf_43 dxf_38 dxf_39 dxf_10 dxf_40 dxf_41 dxf_42 dxf_39 dxf_210 n) (initget "All Select") (if (eq (getkword "\nLWPolylines to break at each vertex? [All/Select] <Select>: ") "All") (setq js (ssget "_X" (list (cons 0 "LWPOLYLINE") (cons 67 (if (eq (getvar "CVPORT") 2) 0 1)) (cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB"))) ) ) i -1 ) (setq js (ssget (list (cons 0 "LWPOLYLINE") (cons 67 (if (eq (getvar "CVPORT") 2) 0 1)) (cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB"))) ) ) i -1 ) ) (cond (js (repeat (sslength js) (setq dxf_obj (entget (setq ent (ssname js (setq i (1+ i)))))) (if (cdr (assoc 43 dxf_obj)) (setq dxf_43 (cdr (assoc 43 dxf_obj))) (setq dxf_43 0.0) ) (if (cdr (assoc 38 dxf_obj)) (setq dxf_38 (cdr (assoc 38 dxf_obj))) (setq dxf_38 0.0) ) (if (cdr (assoc 39 dxf_obj)) (setq dxf_39 (cdr (assoc 39 dxf_obj))) (setq dxf_39 0.0) ) (setq dxf_10 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) dxf_obj)) dxf_40 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 40)) dxf_obj)) dxf_41 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 41)) dxf_obj)) dxf_42 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 42)) dxf_obj)) dxf_210 (cdr (assoc 210 dxf_obj)) ) (if (not (zerop (boole 1 (cdr (assoc 70 dxf_obj)) 1))) (setq dxf_10 (append dxf_10 (list (car dxf_10))) dxf_40 (append dxf_40 (list (car dxf_40))) dxf_41 (append dxf_41 (list (car dxf_41))) dxf_42 (append dxf_42 (list (car dxf_42))) n (cdr (assoc 90 dxf_obj)) ) (setq n (1- (cdr (assoc 90 dxf_obj)))) ) (repeat n (entmake (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (assoc 67 dxf_obj) (assoc 410 dxf_obj) (assoc 8 dxf_obj) (if (assoc 62 dxf_obj) (assoc 62 dxf_obj) (cons 62 256)) (if (assoc 6 dxf_obj) (assoc 6 dxf_obj) (cons 6 "BYLAYER")) (if (assoc 370 dxf_obj) (assoc 370 dxf_obj) (cons 370 -1)) (cons 100 "AcDbPolyline") (cons 90 2) (cons 70 (boole 1 (cdr (assoc 70 dxf_obj)) 128)) (cons 38 dxf_38) (cons 39 dxf_39) (cons 10 (car dxf_10)) (cons 40 (car dxf_40)) (cons 41 (car dxf_41)) (cons 42 (car dxf_42)) (cons 10 (cadr dxf_10)) (cons 40 (cadr dxf_40)) (cons 41 (cadr dxf_41)) (cons 42 (cadr dxf_42)) (assoc 210 dxf_obj) ) ) (setq dxf_10 (cdr dxf_10) dxf_40 (cdr dxf_40) dxf_41 (cdr dxf_41) dxf_42 (cdr dxf_42)) ) (entdel ent) ) (print (sslength js)) (princ " LWpolyline(s) breaked at its vertexs.") ) ) (prin1) ) 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.