Jump to content

How to pick a variable number or points


Alhazred

Recommended Posts

In my routine I have to ask the user to pick some points, all the points he wants.

To do that I've done like this and it works

(setq points nil)
(setq pt (getpoint "\nSelect a point:"))
(while (/= pt nil)
 (setq points (cons pt points))
 (setq pt (getpoint "\nSelect a point:"))
)

In this way, the user, to stop the selection has to right click.

Is there a better way to do the same?

Link to comment
Share on other sites

This is the solution used by AutoCAD also to end a selection cycle. You may add the selection to WHILE test to avoid calling it twice:

 

(while (/= (setq pt (getpoint "\nSelect a point <ENTER to exit>:")) nil)
(setq points (cons pt points))
)

 

 

Regards,

Link to comment
Share on other sites

Here's mine...

 

(defun AT:GetPoints (/ lst pt)
 ;; Return list of picked points
 ;; Alan J. Thompson, 06.18.10
 (if (car (setq lst (list (getpoint "\nSpecify first point: "))))
   (progn
     (while (and (if (> (length lst) 2)
                   (setq pt (initget 0 "Close")
                         pt (getpoint (car lst) "\nSpecify next point [Close]: ")
                   )
                   (setq pt (getpoint (car lst) "\nSpecify next point: "))
                 )
                 (/= pt "Close")
            )
       (mapcar (function (lambda (a b) (and a b (grdraw a b 1 1))))
               (setq lst (cons pt lst))
               (cdr lst)
       )
     )
     (redraw)
     (reverse (cond ((= pt "Close") (cons (last lst) lst))
                    (lst)
              )
     )
   )
 )
)

Edited by alanjt
Link to comment
Share on other sites

A few from my library, some more useful than others

 

;;---------------------=={ Get Points }==---------------------;;
;;                                                            ;;
;;  Returns a list of selected points.                        ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments: - None -                                       ;;
;;------------------------------------------------------------;;
;;  Returns:  List of 3D Points                               ;;
;;------------------------------------------------------------;;

(defun LM:GetPoints ( / lst pt )
 ;; Lee Mac  ~  05.03.10
 ;; Returns a list of selected Points
 
 (if (car (setq lst (list (getpoint "\nPick First Point: "))))
   
   (while (setq pt (getpoint "\nPick Next Point: " (car lst)))
     (mapcar
       (function
         (lambda ( from to ) (grdraw from to 3 1))
       )
       (cdr (reverse (setq lst (cons pt lst))))

       (reverse (cdr lst))
     )
   )
 )
 (redraw) (reverse lst)
)


(defun LM:GetWindow ( / lst pt )
 ;; Lee Mac  ~  05.03.10
 ;; Returns a list of Points defining the window.
 
 (if (car (setq lst (list (getpoint "\nPick First Point: "))))
   
   (while (setq pt (getpoint "\nPick Next Point: " (car lst))) (redraw)
     (mapcar
       (function
         (lambda ( from to ) (grdraw from to 3 1))
       )
       (append lst (list pt)) (setq lst (cons pt lst))
     )
   )
 )
 (redraw) (reverse lst)
)


(defun LM:GetDynWindow ( / lst pt gr )
 ;; Lee Mac  ~  31.01.10

 (if (and (car (setq lst (list (getpoint "\nPick First Point: "))))
          (princ "\nPick Next Point: "))
   (while
     (setq pt
       (progn
         (while (and (= 5 (car (setq gr (grread 't 5 0)))) (listp (cadr gr))) (redraw)
           (mapcar
             (function
               (lambda ( from to ) (grdraw from to 3 1))
             )
             (cons (cadr gr) lst) (append lst (cdr gr))
           )
         )
         (cond ( (listp (cadr gr)) (cadr gr) ))
       )
     )
     (cond ( pt (setq lst (cons pt lst))))
   )
 )
 (redraw) (reverse lst)
)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...