AutoLISP: Break at Intersections With A Gap

Here is a very useful routine that breaks objects at their intersections and then creates a gap at the intersection on the first object that you select.

Here’s how:

  • BI <enter> to start
  • Specify the gap distance.  <enter>
  • (Note: the gap distance that you specify is actually only half of the total gap distance. So if you specify 5 as the gap distance, the distance from the intersection to one side of the gap. Your total gap distance will be 10…)
  • Select the first object [Don’t click enter] (this object will receive the break)
  • Select the second object to define the intersection <enter> or right-click

(Note: this routine does not work on a polyline that intersects itself)

;Written by: Chris Wade

;2010-02-03

;Breaks objects at intersections

(defun c:BreakInt (/ Ent1 Ent1E EntSS ct IntLst ct2 pt1 pt1a bptlist BDis ct3) (vl-load-com)

(if (not (setq BDis (getreal "Enter a gap distance <0.1>: ")))

(setq BDis 0.1)

)

(if (or (/= (getvar "cvport") 1) (/= (getvar "tilemode") 0))

(setq BDis (/ BDis (getvar "cannoscalevalue")))

;;(setq BDis 0.1) <--commented out

)

(princ "\n")

(while (= Ent1 nil)

(setq Ent1 (entsel "\rSelect the object to break: "))

)

(setq Ent1E (vlax-ename->vla-object (car Ent1)))

(princ "\n")

(while (= EntSS nil)

(princ "\rSelect the objects to break with: ")

(setq EntSS (ssget))

)

(setq ct 0)

(while (< ct (sslength EntSS))

(setq intLst (vlax-invoke Ent1E 'intersectWith (vlax-ename->vla-object (ssname EntSS ct)) acExtendNone))

(cond

((/= intLst nil)

(setq ct2 0)

(while (< ct2 (length intLst))

(setq pt1 (list (nth ct2 intLst) (nth (+ ct2 1) intLst) (nth (+ ct2 2) intLst)))

(setq pt1a (vlax-curve-getdistatparam Ent1E (vlax-curve-getparamatpoint Ent1E pt1)))

(cond

((= bptlist nil)

(setq bptlist (list (vlax-curve-getpointatdist Ent1E (- pt1a BDis))))

)

(T

(setq bptlist (append bptlist (list (vlax-curve-getpointatdist Ent1E (- pt1a BDis)))))

)

)

(setq bptlist (append bptlist (list (vlax-curve-getpointatdist Ent1E (+ pt1a BDis)))))

(setq ct2 (+ ct2 3))

)

)

)

(setq ct (+ ct 1))

)

(cond

((/= bptlist nil)

(setq ct3 0)

(while (< ct3 (length bptlist))

(command "._break" "_non" (trans (nth ct3 bptlist) 0 1) "_non" (trans (nth (+ ct3 1) bptlist) 0 1))

(setq ct3 (+ ct3 2))

)

)

)

)

(defun C:BI ()

(c:breakint)

)

~enjoy

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 at Intersections With A Gap

  1. Ed says:

    Chris,

    Thanks for the lisp. It’s exactly what I needed.

    Ed

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