Hi everyone,
I'm looking to see if someone has or can code a lisp that will explode/break a closed pline into individual plines and not a line.
Thanks,
Cadd4la
|
Hi everyone,
I'm looking to see if someone has or can code a lisp that will explode/break a closed pline into individual plines and not a line.
Thanks,
Cadd4la
Maybe something like this?
Code:(defun c:xpline (/ doc oldpedit ss ss1 ss2 n) (vl-load-com) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-StartUndoMark doc) (if (= (getvar "peditaccept") 0) (progn (setq oldpedit (getvar "peditaccept")) (setvar "peditaccept" 1) ) ) (if (setq ss (ssget '((0 . "*POLYLINE")))) (repeat (setq n (sslength ss)) (command "_.explode" (ssname ss (setq n (1- n)))) (repeat (setq ss1 (sslength (setq ss2 (ssget "_P")))) (command "_.pedit" (ssname ss2 (setq ss1 (1- ss1))) "") ) ) ) (if oldpedit (progn (setvar "peditaccept" oldpedit) (setq oldpedit nil) ) (princ) ) (vla-EndUndoMark Doc) (princ) )
Hi,
You can use this if your polylines are LWPOLYLINE.
Break polyline at every vertex and if XData or Object Data (Civil 3D or Map 3D) are keeping for all segments.
Code:(defun c:break_lw_withOD ( / js i ent dxf_obj xd_l dxf_43 dxf_38 dxf_39 dxf_10 dxf_40 dxf_41 dxf_42 dxf_39 dxf_210 n lst_data nwent tbldef ) (initget "All Select") (if (eq (getkword "\nLWPolylines to break at all 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)))) (list "*")) xd_l (assoc -3 dxf_obj) ) (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 (append (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) ) (if xd_l (list xd_l) '()) ) ) (setq dxf_10 (cdr dxf_10) dxf_40 (cdr dxf_40) dxf_41 (cdr dxf_41) dxf_42 (cdr dxf_42) lst_data nil nwent (entlast)) (if (or (numberp (vl-string-search "Map 3D" (vla-get-caption (vlax-get-acad-object)))) (numberp (vl-string-search "Civil 3D" (vla-get-caption (vlax-get-acad-object)))) ) (progn (foreach n (ade_odgettables ent) (setq tbldef (ade_odtabledefn n)) (setq lst_data (cons (mapcar '(lambda (fld) (cons n (cons fld (ade_odgetfield ent n fld 0)))) (mapcar 'cdar (cdr (nth 2 tbldef)))) lst_data)) ) (cond (lst_data (mapcar '(lambda (x) (ade_odaddrecord nwent (caar x)) (foreach el x (ade_odsetfield nwent (car el) (cadr el) 0 (cddr el)))) lst_data) ) ) ) ) ) (entdel ent) ) (print (sslength js)) (princ " LWpolyline(s) breaking at every vertex with XData and/or Object Data.") ) ) (prin1) )
Stusic,
Thank for your code.
Cadd4la
- - - Updated - - -
Bruno,
I like your code and how you can either have all plines selected or just one. Do you think it's possible to have one more option of selecting all on that layer when you select one pline?
Thank you,
Cadd4la
Added two Layer options to Bruno's code:Code:;| Break Polylines into Polyline segments while keeping Object Data http://forums.augi.com/showthread.php?172867-Lisp-needed-to-explode-break-a-closed-pline by Bruno.Valsecchi added Layer option Tom Beauford (load "break_lw_withOD") break_lw_withOD |; (defun c:break_lw_withOD ( / BrOp elay js i ent dxf_obj xd_l dxf_43 dxf_38 dxf_39 dxf_10 dxf_40 dxf_41 dxf_42 dxf_39 dxf_210 n lst_data nwent tbldef ) (initget "All Layer Select") (setq BrOp (getkword "\nLWPolylines to break at all vertex? [All/Layer/Select] <Select>: ")) (cond ((eq BrOp "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 ) ); All ((eq BrOp "Layer") (setq elay (entsel "Select object on Layer or Enter to select Polylines on Current layer: ")) (if (eq elay nil) (setq elay (getvar "clayer")) (setq elay (cdr (assoc 8 (entget(car elay))))) ) (princ "\nSelect polylines on Layer = ") (princ elay) (setq js (ssget "_X" (list (cons 0 "LWPOLYLINE") (cons 8 elay) (cons 67 (if (eq (getvar "CVPORT") 2) 0 1)) (cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB"))) ) ) i -1 ) ); Layer ((eq BrOp "Select") (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 ) ); Select ) (cond (js (repeat (sslength js) (setq dxf_obj (entget (setq ent (ssname js (setq i (1+ i)))) (list "*")) xd_l (assoc -3 dxf_obj) ) (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 (append (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) ) (if xd_l (list xd_l) '()) ) ) (setq dxf_10 (cdr dxf_10) dxf_40 (cdr dxf_40) dxf_41 (cdr dxf_41) dxf_42 (cdr dxf_42) lst_data nil nwent (entlast)) (if (or (numberp (vl-string-search "Map 3D" (vla-get-caption (vlax-get-acad-object)))) (numberp (vl-string-search "Civil 3D" (vla-get-caption (vlax-get-acad-object)))) ) (progn (foreach n (ade_odgettables ent) (setq tbldef (ade_odtabledefn n)) (setq lst_data (cons (mapcar '(lambda (fld) (cons n (cons fld (ade_odgetfield ent n fld 0)))) (mapcar 'cdar (cdr (nth 2 tbldef)))) lst_data)) ) (cond (lst_data (mapcar '(lambda (x) (ade_odaddrecord nwent (caar x)) (foreach el x (ade_odsetfield nwent (car el) (cadr el) 0 (cddr el)))) lst_data) ) ) ) ) ) (entdel ent) ) (print (sslength js)) (princ " LWpolyline(s) breaking at every vertex with XData and/or Object Data.") ) ) (prin1) )
Last edited by Tom Beauford; 2018-12-13 at 08:07 PM.
Tom,
Thank you so much for your input with the code. It works great.
Regards,
Cadd4la