TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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?
-
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.
-
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?
-
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.
-
Here is my old lisp.
;;;=======================[ 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
)
-
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.
-
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.
-
I thought you had a ent_sel sub that accounted for missed picks :-P
-
You can also uses this
(osnap (getpoint msg) "_nea")
-
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.
-
You can also uses this
(osnap (getpoint msg) "_nea")
This still allows for user input, which I don't want.
-
My intent was to suggest osnap ILO closestpointto
-
Try this Will.
(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)
-
Good example Ron. 8-)
-
Good example Ron. 8-)
Thanks CAB :-)