AutoLISP: Break Circle

200 posts!!!!
and still going.

This is my 200th post and I thought that it would be fitting to feature a LISP routine from Lee Mac. Both Lee and Kent Cooper have generously provided many great routines for many AutoCAD users and have inspired others to push the bounds of what LISP routines can do. But to be honest, some of the most simple routines are the best.

This routine will let you break a circle and keep both parts of the circle. Sounds simple right? This seems like something that should be built into AutoCAD but it isn’t. Below is an animation of how the break command destroys a circle.

That’s where this routine steps in to save the day.

Here’s how:

  • CBRK <enter> to start
  • Select circle
  • Pick 2 points where you want the breaks to occur.
  • That’s it…

~enjoy

;;--------------------=={ Circle Break }==--------------------;;

;; ;;

;; Breaks a circle into two arcs and places the arc created ;;

;; from the portion of the circle selected on designated ;;

;; layer. ;;

;;------------------------------------------------------------;;

;; Author: Lee McDonnell, 2010 ;;

;; ;;

;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;

;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;

;;------------------------------------------------------------;;

(defun c:cbrk ( / *error* _StartUndo _EndUndo Clockwise-p Permute

LM:RemovePairs HiddenLayer doc c p1 p2 norm xang cn ra el )

(vl-load-com)

;; © Lee Mac 2010

(setq HiddenLayer "1") ;; Name of Hidden Layer

(defun *error* ( msg )

(if doc (_EndUndo doc))

(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")

(princ (strcat "\n** Error: " msg " **")))

(princ)

)

(defun _StartUndo ( doc ) (_EndUndo doc)

(vla-StartUndoMark doc)

)

(defun _EndUndo ( doc )

(if (= 8 (logand 8 (getvar 'UNDOCTL)))

(vla-EndUndoMark doc)

)

)

(defun clockwise-p ( p1 p2 p3 ) ; Gile

(< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)

)

(defun permute ( a b / c )

(setq c (eval a))

(set a (eval b))

(set b c)

)

(defun LM:RemovePairs ( lst pairs )

(vl-remove-if '(lambda ( pair ) (vl-position (car pair) pairs)) lst)

)

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

(or (tblsearch "LAYER" HiddenLayer)

(vla-Add (vla-get-Layers doc) HiddenLayer)

)

(if

(and

(progn

(while

(progn (setq c (entsel "\nSelect Circle: "))

(cond

( (vl-consp c)

(if (not (eq "CIRCLE" (cdr (assoc 0 (entget (car c))))))

(princ "\n** Invalid Object Selected **")

)

)

)

)

)

c

)

(setq p1 (getpoint "\nSelect First Break Point: "))

(progn

(while (equal p1 (setq p2 (getpoint "\nSelect Second Break Point: ")) 1e-6)

(princ "\n** Points must be distinct **")

)

p2

)

)

(progn (_StartUndo doc)

(setq norm (trans '(0.0 0.0 1.0) 1 0 t)

xAng (angle '(0. 0. 0.) (trans (getvar 'UCSXDIR) 0 norm t)))

(setq p1 (trans (vlax-curve-getClosestPointto (car c) (trans p1 1 0)) 0 norm)

p2 (trans (vlax-curve-getClosestPointto (car c) (trans p2 1 0)) 0 norm)

cn (cdr (assoc 10 (setq el (entget (car c)))))

ra (cdr (assoc 40 el))

)

(if (< (- (angle cn p1) xAng) (- (angle cn p2) xAng))

(permute 'p1 'p2)

)

(

(lambda ( a1 a2 )

(mapcar

(function

(lambda ( la s e )

(entmake

(append (list (cons 0 "ARC") (cons 8 la) (cons 50 s) (cons 51 e))

(LM:RemovePairs el '(0 5 8 100))

)

)

)

)

(if (clockwise-p p1 (trans (cadr c) 1 norm) p2)

(list (cdr (assoc 8 el)) HiddenLayer)

(list HiddenLayer (cdr (assoc 8 el)))

)

(list a1 a2)

(list a2 a1)

)

)

(angle cn p1) (angle cn p2)

)

(entdel (car c))

(_EndUndo doc)

)

)

(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, AutoLISP: Modify, Modifying. Bookmark the permalink.

5 Responses to AutoLISP: Break Circle

  1. Kent Cooper says:

    Thanks for mentioning me. I found this site while trying to find where I had posted some routine, and decided to see what else of mine you have here, and searching for my name led me to this post. One thing I would suggest is that you put in LINKS to where you find things [not just mine], partly because when I revise a routine I’ve posted at the AutoCAD Customization Discusson Group or Cadalyst CAD Tips, I always send the updated version there, but might not think to check whether it’s one you have here, so your version could be old news. With a link, someone who finds something they’re inerested in described here can go to one of those other sites and get the most current new-and-improved version.
    On this breaking-a-Circle-into-two-Arcs topic: I tried Lee’s routine, which is good as far as it goes. But it runs into trouble with different coordinate systems, and if current entity property overrides [linetype, color, etc.] differ from those of the Circle, the resulting Arcs don’t match the Circle, and it has to leave the original Circle there if it’s on a locked Layer. [I also think its prompt should include some indication that the Circle should be selected on the part of it that you want put on the different Layer.] I took a different approach to most of it [I kept his method of ensuring distinct break points], and came up with a routine that handles all those odd-ball possibilities [and is also a lot shorter], and I also made a version that simply splits the Circle into two Arcs which both stay on the Circle’s Layer. Are you interested? Let me know how to get it/them to you — I don’t see any way of attaching a file here, and I don’t want to paste all the code into this message.

    • AutoCAD Tips says:

      I think that I will edit this post or make a new one that links to your new routine.
      I like the features of your routine.

      Good point Kent. For some routines that I have featured from a long time ago I did not include the link because I didn’t even think of the possibility or need to update the routines. I have since started to include the links as a commented section within the code. I will start to make an additional link within the post as well. I have wondered if should even include posting the code in my posts or simply having a direct link. Being that people are copying the code form here and then asking me to to update the code because of an issue I think that for now on I will leave out the code and give the link. That way you (the author) are aware of any issues.
      I do apologize for not including the links to where the code was from.
      Thanks for all that you do Kent
      ~Greg

  2. Beekeeper says:

    Hello guys. Is possible to get Kents version of this routine somewhere? I tried to find it, but with no success. Thanks a lot.

    • AutoCAD Tips says:

      I am unaware of a version of Kent’s that Breaks a circle. I think that the comment he left in this post was a general request for me to start linking to the original forums where the code was posted so that newer versions and changes would be easier to keep track of.
      The only circle break routine I know of is the one by Lee…
      ~Greg

  3. Pingback: Use break command In order to split objects in AutoCAD. | hedproject

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