AutoLISP: Break Polyline Segments

Here’s a great routine that lets you break a polyline segment. Simply select the segment that you want to be a separate polyline entity from the ones that it was initially created with. This routine works on closed polylines line rectangles… But there is one glitch that I have found. When used on polygons, it creates an extra break.

Here’s how to use it:

  • BSEG <enter> to start
  • Select the segment on a polyline to break
  • That’s it

Below is an example of the routine used on a polyline

Below is an example of the routine used on closed polylines and a polygon

(defun c:BSeg (/ *error* AT:GetSel _isLocked ent seg)

;; Break polyline Segment

;; Alan J. Thompson, 06.16.11

(vl-load-com)

(defun *error* (msg)

(and *AcadDoc* (vla-endundomark *AcadDoc*))

(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))

(princ (strcat "\nError: " msg))

)

)

(defun AT:GetSel (meth msg fnc / ent)

;; meth - selection method (entsel, nentsel, nentselp)

;; msg - message to display (nil for default)

;; fnc - optional function to apply to selected object

;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC")))

;; Alan J. Thompson, 05.25.10

(setvar 'ERRNO 0)

(while

(progn (setq ent (meth (cond (msg)

("\nSelect object: ")

)

)

)

(cond ((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again."))

((eq (type (car ent)) 'ENAME)

(if (and fnc (not (fnc ent)))

(princ "\nInvalid object!")

)

)

)

)

)

ent

)

(defun _isUnLocked (layer) (/= 4 (logand 4 (cdr (assoc 70 (entget (tblobjname "LAYER" layer)))))))

(vla-startundomark

(cond (*AcadDoc*)

((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))

)

)

(if (setq ent

(car (AT:GetSel entsel

"\nSelect polyline segment to break: "

(lambda (x / d p)

(if (and (_isUnLocked (cdr (assoc 8 (setq d (entget (car x))))))

(wcmatch (cdr (assoc 0 d)) "*POLYLINE")

(>= (cdr (assoc 90 d)) 3)

)

(setq seg (list (trans (vlax-curve-getPointAtParam

(car x)

(setq p (fix (vlax-curve-getParamAtPoint

(car x)

(vlax-curve-getClosestPointTo

(car x)

(trans (cadr x) 1 0)

)

)

)

)

)

0

1

)

(trans (cond ((vlax-curve-getPointAtParam (car x) (1+ p)))

((vlax-curve-getPointAtParam (car x) (1- p)))

)

0

1

)

)

)

)

)

)

)

)

(progn (vl-cmdf "_.break" ent "_F" "_non" (car seg) "_non" (car seg))

(vl-cmdf "_.break" (entlast) "_F" "_non" (cadr seg) "_non" (cadr seg))

)

)

(*error* nil)

(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.

2 Responses to AutoLISP: Break Polyline Segments

  1. Juan says:

    If i want remove various segments of differents polylines over the same place? Can you help me?

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