What's wrong with this code?

Discussion in 'AutoCAD' started by kzalec, Dec 3, 2004.

  1. kzalec

    kzalec Guest

    The following very simple .LSP routine doesn't seem to work. I got it out of a textbook on AutoLISP which seems to have a lot of errors in it:

    ;This program is supposed to delete all objects that are within the drawing limits.

    (defun c:delall ()
    (setvar "cmdecho" 0)
    (setq pt1 (getvar "limmin"))
    (setq pt2 (getvar "limmax"))
    (setq ss1 (ssget "c" pt1 pt2))
    (command "redraw")
    (setvar "cmdecho" 1)
    (princ)
    )
     
    kzalec, Dec 3, 2004
    #1
  2. kzalec

    T.Willey Guest

    You have no erase command within you routine. All you are doing is getting two points, then selecting everything within the points with a crossing window.

    Tim

    Try this.

    (defun c:delall ()
    (setvar "cmdecho" 0)
    (setq pt1 (getvar "limmin"))
    (setq pt2 (getvar "limmax"))
    (setq ss1 (ssget "c" pt1 pt2))
    (command "_.erase" ss1 "")
    (setvar "cmdecho" 1)
    (princ)
    )

    ps. You might want to make your variables local. To do so, change the first line to
    (defun c:DelAll (/ pt1 pt2 ss1)
     
    T.Willey, Dec 3, 2004
    #2
  3. kzalec

    kzalec Guest

    Thank you. I feel really dumb for not seeing this even though it was missing from the book! Also, that's a good idea to make the variables to local.
     
    kzalec, Dec 3, 2004
    #3
  4. kzalec

    T.Willey Guest

    Don't worry about it. We all miss something easy once in awhile.

    Happy to help.
    Tim
     
    T.Willey, Dec 3, 2004
    #4
  5. kzalec

    ECCAD Guest

    This is also a way to erase everything.
    Use with care..:)

    (setq ss (ssget "all"))
    (command "_erase" ss "")

    Bob
     
    ECCAD, Dec 3, 2004
    #5
  6. kzalec

    kzalec Guest

    Thanks, Bob.
     
    kzalec, Dec 3, 2004
    #6
  7. kzalec

    T.Willey Guest

    Will this way pick things up that are on a layer that is turned off? I have had bad experience with the "all" option of erase.

    Tim
     
    T.Willey, Dec 3, 2004
    #7
  8. kzalec

    OLD-CADaver Guest

    Use X rather than "all", as in (ssget "X")

    (command ".erase" (ssget"X") "")

    Should erase everything (on/off/frozen) in the current space. Will not touch locked layers.
     
    OLD-CADaver, Dec 3, 2004
    #8
  9. kzalec

    ECCAD Guest

    Tim,
    I just tried "all" on a drawing with several layers 'off', and
    several layers 'locked'. It picks up the 'off' but won't touch
    the 'locked'. You would have to 'unlock' all the layers first, if
    you want "all" to erase these also.
    Same results with (setq ss (ssget "X"))

    Bob
     
    ECCAD, Dec 3, 2004
    #9
  10. kzalec

    T.Willey Guest

    Bob,

    I thought that might happen. I think the way that the OP was going to select things is a little better then, at least while the OP is learning. This way the OP knows what they are selecting.

    Thanks for confirming it.
    Tim
     
    T.Willey, Dec 4, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.