TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: whdjr on February 20, 2009, 09:47:45 AM

Title: How to get a user to pick a point?
Post by: whdjr on February 20, 2009, 09:47:45 AM
I want a user to pick an arbitrary point near a line.  I was using the getpoint function but it allows for the user to type in a point and I want to limit it to only picked points.  What is a good way/method to get the user to "pick" a point?  I thought of using entsel but if nothing is at the pick point it just returns nil.  Any ideas?
Title: Re: How to get a user to pick a point?
Post by: CAB on February 20, 2009, 09:54:17 AM
You can use (initget 128) which turns any entry from the keyboard into a string so
you can then reject the entry and stay in the pick point loop.
Title: Re: How to get a user to pick a point?
Post by: whdjr on February 20, 2009, 10:00:14 AM
That is a good idea CAB.

What do you think about this?
I think I might just use entsel and check to make sure they pick a point on the object.

Which would u prefer to use?
Title: Re: How to get a user to pick a point?
Post by: ronjonp on February 20, 2009, 10:09:55 AM
That is a good idea CAB.

What do you think about this?
I think I might just use entsel and check to make sure they pick a point on the object.

Which would u prefer to use?

You could also use entsel and vlax-curve-getclosestpointto if the point needs to lie on the object.
Title: Re: How to get a user to pick a point?
Post by: CAB on February 20, 2009, 10:11:03 AM
Here is my old lisp.
Code: [Select]
;;;=======================[ getpoint_only.lsp ]=======================
;;; Author: Charles Alan Butler [CAB @ TheSwamp.org
;;; Version:  1.0 Jun. 16, 2005
;;; Purpose: Only get a point, do not return without one
;;; Sub_Routines: -None
;;; Arguments: msg  string containing the prompt message
;;;            p1  may be nil or a point
;;; Usage:  (getpoint_only msg p1)
;;; Returns: -the point picked
;;; Note: -User may enter a point at the command line 10,10 or 10,10,0
;;;====================================================================
;;  This is an attempt at preventing the user from entering a distance
;;  which ACAD uses with the cursor direction to derive the new point.

(defun getpoint_only (msg p1 / pt loop fuzz lastp)
  (or msg (setq msg "\n"))
  (while
    (progn
      (initget 128)
      (if (and p1 (listp p1))
        (setq pt (getpoint p1 msg))
        (setq pt (getpoint msg))
      )
      (if (or (null pt) (= (type pt) 'STR))
        (princ "\nPick point only, Try Again.")
      )
    )
  )
  pt
)
Title: Re: How to get a user to pick a point?
Post by: whdjr on February 20, 2009, 10:15:35 AM
You could also use entsel and vlax-curve-getclosestpointto if the point needs to lie on the object.

This is my intention within the program, but I felt I needed to validate the point first.  Entsel will retun nil if nothing is selected and getpoint can accept user input instead of a picked point.
Title: Re: How to get a user to pick a point?
Post by: whdjr on February 20, 2009, 10:17:27 AM
CAB, your code is very well and would work in this situation however I think I am going to use entsel and force the user to pick a point on the line.  I think it flows better with the intention of the program.

Thanks for the thoughts.
Title: Re: How to get a user to pick a point?
Post by: ronjonp on February 20, 2009, 10:17:44 AM
I thought you had a ent_sel sub that accounted for missed picks  :-P
Title: Re: How to get a user to pick a point?
Post by: CAB on February 20, 2009, 10:19:03 AM
You can also uses this
Code: [Select]
(osnap (getpoint msg) "_nea")
Title: Re: How to get a user to pick a point?
Post by: whdjr on February 20, 2009, 10:51:18 AM
I thought you had a ent_sel sub that accounted for missed picks  :-P
Yes it does, but entsel will return nil if nothing is in the pickbox.  I can modify it I just wanted to know if anyone had a different approach.
Title: Re: How to get a user to pick a point?
Post by: whdjr on February 20, 2009, 10:51:54 AM
You can also uses this
Code: [Select]
(osnap (getpoint msg) "_nea")
This still allows for user input, which I don't want.
Title: Re: How to get a user to pick a point?
Post by: CAB on February 20, 2009, 11:05:58 AM
My intent was to suggest osnap ILO closestpointto
Title: Re: How to get a user to pick a point?
Post by: ronjonp on February 20, 2009, 11:29:56 AM
Try this Will.

Code: [Select]
(defun pp (/ out pt)
  (while (and (setq pt (grread 5)) (= (car pt) 5))
    (redraw)
    (if (setq out (osnap (cadr pt) "_nea"))
      (progn (grdraw out
                     (polar out (angtof "45") (* 0.025 (getvar 'viewsize)))
                     1
             )
             (princ "\rYou're near something pick now! ")
      )
      (progn (setq out (cadr pt))
             (princ "\rYou're NOT near something don't pick! ")
      )
    )
  )
  out
)
(pp)
Title: Re: How to get a user to pick a point?
Post by: CAB on February 20, 2009, 11:57:30 AM
Good example Ron. 8-)
Title: Re: How to get a user to pick a point?
Post by: ronjonp on February 20, 2009, 12:47:06 PM
Good example Ron. 8-)

Thanks CAB  :-)