See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Lisp needed to explode/break a closed pline

  1. #1
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    346
    Login to Give a bone
    0

    Default Lisp needed to explode/break a closed pline

    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
    AutoCAD 2010 Windows7 Ultimate
    _________________________________________________________
    My spelling is wobbly. It's good spelling but it wobbles and the letters get in the wrong places.
    ... Winnie the Pooh

  2. #2
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,514
    Login to Give a bone
    0

    Default Re: Lisp needed to explode/break a closed pline

    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)
    )
    Phillip Bradshaw
    Lead Pixel Pusher, Lucid Design Studio
    CAD Detailer, Proctor Productions

    A doctor can bury his mistakes but an architect can only advise his clients to plant vines. - Frank Lloyd Wright

  3. #3
    100 Club
    Join Date
    2002-08
    Posts
    180
    Login to Give a bone
    1

    Default Re: Lisp needed to explode/break a closed pline

    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)
    )

  4. #4
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    346
    Login to Give a bone
    0

    Default Re: Lisp needed to explode/break a closed pline

    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
    AutoCAD 2010 Windows7 Ultimate
    _________________________________________________________
    My spelling is wobbly. It's good spelling but it wobbles and the letters get in the wrong places.
    ... Winnie the Pooh

  5. #5
    100 Club
    Join Date
    2002-08
    Posts
    180
    Login to Give a bone
    0

    Default Re: Lisp needed to explode/break a closed pline

    Quote Originally Posted by cadd4la View Post
    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
    You can use 'FILTER command before use break_lw_withOD and option "select" for obtain previous objects filtering

  6. #6
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL
    Posts
    3,078
    Login to Give a bone
    0

    Default Re: Lisp needed to explode/break a closed pline

    Quote Originally Posted by Bruno.Valsecchi View Post
    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 Beauford P.S.M. - Civil 2019 on Windows 10 Enterprise
    Design Analysis - Leon County Public Works/Engineering Wrap [CODE] tags around selected text
    2280 Miccosukee Rd. Tallahassee, FL 32308-5310
    Ph# (850)606-1516 Home Page

  7. #7
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    346
    Login to Give a bone
    0

    Default Re: Lisp needed to explode/break a closed pline

    Tom,

    Thank you so much for your input with the code. It works great.

    Regards,

    Cadd4la
    AutoCAD 2010 Windows7 Ultimate
    _________________________________________________________
    My spelling is wobbly. It's good spelling but it wobbles and the letters get in the wrong places.
    ... Winnie the Pooh

Similar Threads

  1. Replies: 1
    Last Post: 2018-04-07, 01:31 AM
  2. Replies: 2
    Last Post: 2017-05-29, 12:41 PM
  3. Cad etiquette question on a CLOSEd pline
    By tufofi in forum CAD Standards
    Replies: 4
    Last Post: 2011-06-21, 11:28 PM
  4. break pline into equal segments
    By John MacFall in forum AutoCAD General
    Replies: 1
    Last Post: 2007-09-25, 05:29 PM
  5. Explode in LISP Does Not Explode Selection Set
    By Kevin Janik in forum AutoLISP
    Replies: 5
    Last Post: 2004-12-07, 10:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •