Bill Tillman Posted June 9, 2017 Share Posted June 9, 2017 I'm using a small LISP program to take two input points and work with them. (prompt "\nSelect First Point\n") (setq p1 (getpoint)) (prompt "\nSelect Second Point\n") (setq p2 (getpoint)) ... Do some stuff I'd like to have the code keep repeating until the user is finished. I think a while loop is in order but when I place the while above or below the first input point I don't get the desired results. I need the code to reset the OSMODE and PICKBOX variables when it's done but pressing escape doesn't allow for this unless I do some more error trapping. If I place the while after the first input the code keeps trying to get the second point. I'd like the code to exit cleanly if the user pressed enter on the first input. Quote Link to comment Share on other sites More sharing options...
tombu Posted June 9, 2017 Share Posted June 9, 2017 Error trapping is always useful for any lisp that requires user input. We would need to see the rest of the code to see how best to loop it and what to put in an *ERROR* localized function. Quote Link to comment Share on other sites More sharing options...
Bill Tillman Posted June 9, 2017 Author Share Posted June 9, 2017 Here is the complete code. It's a quick tool to get pickets for fencing drawn and spaced equally along a given length of fence. The code works fine but right now it only works once and the user has to start it again to do another length of fence. I'd like to get it working to allow it to run then keep running as long as the user selects a new first point. If they press enter then I'd like it to exit cleanly. I have an *error* trapping routine which will handle the user pressing escape. That will be easy to load when this runs. The trick I'm looking for is how to quit cleanly by pressing Enter when asked for the point input. (vl-load-com) (defun C:pickets (/ picketthk picketoc) (setq *current_osmode (getvar 'OSMODE) *current_pickbox (getvar 'PICKBOX) ) ;;; Set up common variables (setq picketthk 0.75 picketoc 4. ) (prompt "\nSelect First Point\n") (setq p1 (getpoint)) (prompt "\nSelect Second Point\n") (setq p2 (getpoint)) (setvar 'OSMODE 0) (setvar 'PICKBOX 0) (setq d (distance p1 p2) numpickets (/ d picketoc) firstbay (+ (/ (- d (* (fix numpickets) picketoc)) 2.) (/ picketthk 2.)) ) (if (< firstbay (+ (/ picketoc 2.) (/ picketthk 2.))) (setq firstbay (+ firstbay (- (/ picketoc 2.) (/ picketthk 2.)))) ) ;;; if the number pf pickets divided by picketoc is has no remainder subtract 1 picket and increase firstbay dimension (if (= (/ d (fix numpickets)) (fix (/ d (fix numpickets)))) (setq numpickets (1- numpickets) firstbay (+ firstbay (- picketoc (/ picketthk 2.))) ) ) (setq count 0) (repeat (fix numpickets) (DrawPicket "picket" (polar p1 0 (+ firstbay (* picketoc count)))) (setq count (1+ count)) ) (setvar 'OSMODE *current_osmode) (setvar 'PICKBOX *current_pickbox) (princ) ); end pickets (defun DrawPicket (PicketBlk pt) (entmakex (list (cons 0 "INSERT") (cons 2 PicketBlk) (cons 8 "Pickets") (cons 10 pt) (cons 41 1.0) ; Scale Factor (cons 42 1.0) ; Scale Factor (cons 43 1.0) ; Scale Factor ) ) (princ) ); end DrawPicket Quote Link to comment Share on other sites More sharing options...
Grrr Posted June 9, 2017 Share Posted June 9, 2017 Something like this, I guess (quickly revised) : (vl-load-com) (defun C:pickets (/ *error* picketthk picketoc p1 p2 d numpickets firstbay count ) (defun *error* ( m ) (and vars (mapcar 'setvar '(osmode pickbox) vars)) (princ m) (princ) ) (setq vars (mapcar 'getvar '(osmode pickbox))) ;;; Set up common variables (setq picketthk 0.75 picketoc 4. ) (while (and (setq p1 (getpoint "\nSelect First Point: ")) (setq p2 (getpoint p1 "\nSelect Second Point: ")) ) (mapcar 'setvar '(osmode pickbox) '(0 0)) (setq d (distance p1 p2) numpickets (fix (/ d picketoc)) firstbay (+ (/ (- d (* numpickets picketoc)) 2.) (/ picketthk 2.)) ) (if (< firstbay (+ (/ picketoc 2.) (/ picketthk 2.))) (setq firstbay (+ firstbay (- (/ picketoc 2.) (/ picketthk 2.)))) ) ;;; if the number pf pickets divided by picketoc is has no remainder subtract 1 picket and increase firstbay dimension (if (= (/ d (fix numpickets)) (fix (/ d numpickets))) (setq numpickets (1- numpickets) firstbay (+ firstbay (- picketoc (/ picketthk 2.))) ) ) (repeat numpickets (DrawPicket "picket" (polar p1 0 (+ firstbay (* picketoc numpickets)))) (setq numpickets (1- numpickets)) ) (mapcar 'setvar '(osmode pickbox) vars) ); while (princ) ); end pickets (defun DrawPicket (PicketBlk pt) (entmakex (list (cons 0 "INSERT") (cons 2 PicketBlk) (cons 8 "Pickets") (cons 10 pt) (cons 41 1.0) ; Scale Factor (cons 42 1.0) ; Scale Factor (cons 43 1.0) ; Scale Factor ) ) ); end DrawPicket Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 9, 2017 Share Posted June 9, 2017 Grr beat me to it i use this a lot (while (setq pt (getpoint "Pick point - Press enter to exit")) (alert "picked") ) (alert "ended") Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.