Exiting a lisp routine

Discussion in 'AutoCAD' started by JeffZ, Aug 12, 2004.

  1. JeffZ

    JeffZ Guest

    I'm pretty sure what I'm trying to figure out has something to do with error handling, but as simple as everything makes it sound I still can't figure it out.

    I want to be able to right click and exit my command, just like in many regular Autocad commands.

    I'm using this to increase a chosen number by 1 and maybe add a letter to it too. For example, say I have a list of numbers, 1-10. I start the command, enter the number I want to start with (5), choose a letter to go with it, (B), then select the first number (1) it changes to B5, the next item I select will change to B6 and so on...

    What I would like to be able to do is right click before entering the starting number (or really any time) and cancel the command.

    I'd also like to be able to use "undo" within the command to go back steps without having to undo everything in case I change my mind.

    Here's my file...
     
    JeffZ, Aug 12, 2004
    #1
  2. JeffZ

    Paul Turvill Guest

    Just use a (while ...) loop with your initial (setq ...):

    (while (setq Item (entsel "\nPick a number))
    (do stuff here if Item was picked)
    (do more stuff)
    (etc.)
    );; end while
    [routine jumps to here if no Item is selected]
    ___

    regular Autocad commands.
     
    Paul Turvill, Aug 13, 2004
    #2
  3. JeffZ

    JeffZ Guest

    If I put the WHILE before my first setq, then it goes back to that step each time. The first two steps need to happen once, then loop through the rest. I'd like to be able to right-click out before it gets to the looping part.

    I think I can put a while around the first two, but I'm not really sure what to sure to tell WHILE to test. I'm also not exactly how WHILE works without something to test against.

    i.e. (while (setq Item (entsel "\nPick a number))

    I understand while when it looks like this

    (while (this is true)
    (do this)
    (otherwise do this)
    )
     
    JeffZ, Aug 13, 2004
    #3
  4. JeffZ

    Paul Turvill Guest

    each time. The first two steps need to happen once, then loop through the
    rest. I'd like to be able to right-click out before it gets to the looping
    part.
    what to sure to tell WHILE to test. I'm also not exactly how WHILE works
    without something to test against.
     
    Paul Turvill, Aug 13, 2004
    #4
  5. JeffZ

    Paul Turvill Guest

    No, you don't. You can't use (while) in this manner. Use (if ...) to choose
    between two options.

    In my example, the loop just continues asking for a new value, then
    processing it until you hit ENTER without selecting an object. Since the
    non-selection returns nil, the (while) loop terminates when you hit ENTER
    (or right click, if your mouse is programmed correctly).
    ..___
     
    Paul Turvill, Aug 13, 2004
    #5
  6. JeffZ

    T.Willey Guest

    This is how I handle it:
    (setvar "errno" 0)
    (while (and (/= (getvar "errno") 52) (not ob1))
    (setq ob1 (entsel "\nSelect object: "))
    )
    This will prompt the user to select object until one is selected, or he hits enter (either right click, or keyboard).

    Tim
     
    T.Willey, Aug 13, 2004
    #6
  7. JeffZ

    JeffZ Guest

    You're right, while doesn't act like that. I was thinking wrong.
     
    JeffZ, Aug 13, 2004
    #7
  8. JeffZ

    JeffZ Guest

    Tim - thanks for the option.

    Paul - musta done something wrong the first time. I went back and put the while in front of everything and it worked just fine, except for returning a nil at the end. And a (princ) took care of that.
     
    JeffZ, Aug 13, 2004
    #8
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.