ellen finkelstein logo

Ellen Finkelstein.com
AutoCAD PowerPoint About Links
       

Over 130 AutoCAD tips and tutorials!

AutoCAD Tips
AutoCAD Tips Blog

Get free tips!
Sign up for our monthly tips newsletter. Free, bonus e-booklet!


RSS: What is it? Why do I want it? How do I get it?

Add to My Yahoo!
Subscribe with Bloglines

Buy a Book

E-mail This Page 
to a Friend

Submit a tip! If you include your name and I post your tip, I'll give you credit.

AutoCAD Tips & Tutorials

Break objects quickly

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)
(terpri)
(setq breakpoint (getpoint "Specify the break point "))
(setq object (ssget breakpoint))
(command "_break" object breakpoint "@")
(princ)
)

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 Hyperpics.com. 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)
  (terpri)
   ;; Set a single object
  (if (setq object (ssget ":S"))
    (progn
      ;; 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
        (progn
            (prompt "\nNo point selected.")
            (redraw (ssname object 0) 4)
        )
      )
    )
     ;; Inform the user that no object was selected
    (prompt "\nNo object selected")
  )
 (princ)
)

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)
 (terpri)
 (setq object (entsel))
 (setq breakpoint (getpoint "pick  breakpoint "))
  (command "break" object "f" breakpoint "@")
 (princ)
)

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!

 

 

 

Back to main tips menu for more tips

Page copy protected against web site content infringement by Copyscape


Books by Ellen
 

AutoCAD 2008 and AutoCAD LT 2008 Bible
Learn the great new features with wide application to all disciplines. Get the most comprehensive book on AutoCAD! DVD contains a 30-day trial of AutoCAD and AutoCAD LT. Thorough exercises guide you through each feature.

AutoCAD 2007 and AutoCAD LT 2007 Bible 
Discover the 2007 features, especially the radically improved 3D tools. CD has AutoCAD 30-day trial, 3rd-party software, and drawings for exercises.

AutoCAD 2006 and AutoCAD LT 2006 Bible 
Understand and use the 2006 features, including dynamic blocks and the new method of customizing menus and toolbars. CD-ROM has AutoCAD trial, software, and drawings for all exercises.


AutoCAD 2005 and AutoCAD LT 2005 Bible
Fully explains latest 2005 features:  tables, fields, and sheet sets. For the first time, covers AutoCAD LT! CD-ROM comes with software and drawings for all exercises.


AutoCAD 2004 Bible

Covers all features in detail. Hands-on exercises. Over 1300 pages + CD-ROM with software and drawings for all exercises.

                                  Home  |  AutoCAD  |  PowerPoint  | E-StoreAbout  | Links | Contact | Site Map
Copyright Ellen Finkelstein, Inc.