AutoCAD 2015 and AutoCAD LT 2015 Bible

The most comprehensive AutoCAD book around!

Break objects quickly in AutoCAD

Michael Tabacinic sent me this e-mail:

“First off, I’d like to say, love your blog and love your tips; So helpful! Especially the last one; coincidentally, I had been asking our CAD manager for the past three weeks if there was a way to give the “Break at Point” command (^C^C_break \_f \@ ) an alias, so that when we type “br” it does that instead of the regular “break” command.

“Your tip doesn’t exactly solve the issue, but it helps a little; I figured I might as well ask: Any idea how to achieve what I’ve been trying to do for weeks? (The CAD manager said he’d look into a solution through lsp programming, but hasn’t found anything so far)”

The tip Michael mentioned explains how to create a keyboard shortcut, but he wanted to type br. To do this, you need to create an AutoLISP command with that name. Michael’s question launched me into an effort to write an AutoLISP program. However, for some reason, I tried to write a program that would break an object at the original point specified, so that you could break an object with one point specification.

First of all, that’s not what Michael was asking for. His menu macro is equivalent to the Break at Point button on the Modify toolbar, which requires you to first select the object and then specify the break point.

Second, I already had an AutoLISP program that breaks an object with one point specification. It’s from Alan Praysman and available as a free download with my Breaking a Line into Two tip.

But lots of interesting code came out of the process, so I thought I’d share it with you.

I’m not a programmer, so anything I write is very amateurish. But here’s what I came up with (note that I used bap instead of br):

;;;breaks object at the point you use to select it
(defun c:bap (/ object breakpoint)
(setq breakpoint (getpoint “Specify the break point “))
(setq object (ssget breakpoint))
(command “_break” object breakpoint “@”)

I sent this back to Michael, noting that it doesn’t have any error trapping. Specifically, it just fails if you don’t select an object.

It defines a command, BAP, that asks for a break point. You can use an object snap. Then it breaks the object at that point.

Meanwhile, I sent this to Lee Ambrosius of Lee is a real programmer and he sent this back. He notes that even this code is missing some error trapping for the situation where a user presses Esc before breaking the line.

(defun c:bap ( / object breakpoint)
;; Set a single object
(if (setq object (ssget “:S”))
;; Use the redraw function to highlight the selected object
(redraw (ssname object 0) 3)
;; Get the second break point
(if (setq breakpoint (getpoint “\nSpecify the break point “))
;; Use the Break command to break the selected object at the selected point
(command “._break” object breakpoint “@”)
;; Inform the user that no point was selected
(prompt “\nNo point selected.”)
(redraw (ssname object 0) 4)
;; Inform the user that no object was selected
(prompt “\nNo object selected”)

This code does the same thing as mine, but adds some error trapping and a couple of other nice features.

Meanwhile, Michael replied:

“Thank you very much for your help Ellen. I used your LISP function to learn how LISP works, and then tweaked it to get it to do what I wanted. I’m not sure how well it works, as I’m not a programmer either, so I don’t know if it’s foolproof, but it does what I need it to so far. . “

“The main reason I had to tweak your version was because if two lines (or more) crossed each other, I could only use the command on the line that was on top in the drawing order, which wasn’t always the one I wanted.

“There was another problem too, which my LISP command can’t solve either. . . The problem is the following: The point I want too break a line at is where a 2nd line would intersect it if I were to extend it. To select this point, I drag an OTRACK line that extends from the 2nd line to the intersection. But when I click on the intersection, either the line stays intact, or the line breaks at a different point.

“When I perform the same actions using the “Break At Point” icon in the “Modify” toolbar, it does what I want it to. I’m not sure if it’s a LISP thing, or if it has to do with my AutoCAD settings, or with the program itself, or something else. If you have any ideas on that, I’d love it if you could send them over hear to help me solve this… otherwise I’ll have to settle for the tweaked LISP command…”

Here is Michael’s code:

;;;breaks selected object at the point you pick
(defun c:bap (/ object breakpoint)
(setq object (entsel))
(setq breakpoint (getpoint “pick breakpoint “))
(command “break” object “f” breakpoint “@”)

Now, you have four AutoLISP routines that can help you break objects quickly. You can see how even non-programmers can enjoy writing code and create something useful. Of course, you need to know something about AutoLISP, but amateurs can still create very useful programs. Give it a try!

Ellen Finkelstein

2 comments to Break objects quickly in AutoCAD

  • david

    just “br” enter, shift+rightClick -> f.e.endpoint

  • Mike

    This is something that I have been looking for with one addition. Is there anyway to put a dimension in the code so the break has a gap of said dimension?

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>