Author Topic: How to get a user to pick a point?  (Read 4434 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
How to get a user to pick a point?
« 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?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get a user to pick a point?
« Reply #1 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Re: How to get a user to pick a point?
« Reply #2 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?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to get a user to pick a point?
« Reply #3 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get a user to pick a point?
« Reply #4 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
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Re: How to get a user to pick a point?
« Reply #5 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.

whdjr

  • Guest
Re: How to get a user to pick a point?
« Reply #6 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.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to get a user to pick a point?
« Reply #7 on: February 20, 2009, 10:17:44 AM »
I thought you had a ent_sel sub that accounted for missed picks  :-P

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get a user to pick a point?
« Reply #8 on: February 20, 2009, 10:19:03 AM »
You can also uses this
Code: [Select]
(osnap (getpoint msg) "_nea")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Re: How to get a user to pick a point?
« Reply #9 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.

whdjr

  • Guest
Re: How to get a user to pick a point?
« Reply #10 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get a user to pick a point?
« Reply #11 on: February 20, 2009, 11:05:58 AM »
My intent was to suggest osnap ILO closestpointto
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to get a user to pick a point?
« Reply #12 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)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to get a user to pick a point?
« Reply #13 on: February 20, 2009, 11:57:30 AM »
Good example Ron. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: How to get a user to pick a point?
« Reply #14 on: February 20, 2009, 12:47:06 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC