AutoLISP: Break Polyline at Vertex

You can always explode a Polyline if you need to break your polyline into individual segments. This method will make the polyline into individual lines. But what if you would like these individual segments to remain individual polylines? That’s where this routine comes in handy.

Here’s how:

  • BPV <enter> to start Break Polyline Vertex
  • Select the polyline(s) <enter>

 

(defun c:BPV (/ _chop ss i e)

;; Break lwPolyline at each Vertex

;; Alan J. Thompson, 09.14.11

(vl-load-com)

(defun _chop (lst e)

(if (vlax-curve-isClosed e)

(cdr lst)

(reverse (cdr (reverse (cdr lst))))

)

)

(if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE") (-4 . ">") (90 . 2))))

(repeat (setq i (sslength ss))

(foreach point (_chop (apply 'append

(mapcar '(lambda (x)

(if (eq (car x) 10)

(list (trans (cdr x) 0 1))

)

)

(entget (setq e (ssname ss (setq i (1- i)))))

)

)

e

)

(vl-cmdf "_.break" e "_F" "_non" point "_non" point)

(setq e (entlast))

)

)

)

(princ)

)

 

 

Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, Modifying, Polylines. Bookmark the permalink.

One Response to AutoLISP: Break Polyline at Vertex

  1. robert says:

    A great perspective, but this does not work in my cad, could there be a bug?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s