TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Shade on March 10, 2006, 09:52:58 AM
-
How does one test for a point?
Example code...
(initget "Options")
(setq PNT (getpoint "\nSelect Point, <O>ptions: "));
(if (not PNT [color=Red]Point[/color])
(OPTIONS)
);
I thought of testing the variable PNT to see if its a list, but I would like to know if there is a better more secure way of testing for a point
Thanks in advance for any help...
Shade
-
If you want to see if it is a point (list) then you can use the "type" function on the variable.
(if (= (type Pnt) 'LIST)
.... do whatever
... or do your options thingy here.
)
??
-
Here is my "Over The Top" routine. :-o
;;;=======================[ getpoint_only.lsp ]=======================
;;; Author: Charles Alan Butler
;;; 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
;;; Usage: (getpoint_only msg)
;;; 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 / pt loop fuzz lastp)
(setq loop t
fuzz 0.0001
lastp (getvar "lastpoint")
)
(setq msg (strcat "\n" (cond (msg) ("Please select a point: "))))
;; in case the user pressed escape last time here
(if (< fuzz (distance '(1.9999 1.9999 0.0) (getvar "lastpoint")))
(setvar "lastpoint" '(1.9999 1.9999 0.0))
(setvar "lastpoint" '(1.8999 1.8999 0.0))
)
(while loop
;; pt must meet the following requirements
(if (and (setq pt (getpoint msg)) ; not nil
(listp pt) ; must be a list
;; do not allow bad numeric entry
(< fuzz (distance pt (getvar "lastpoint")))
)
(setq loop nil) ; ok to exit, else
(prompt "\nYou must select a point, please try again. ")
)
)
(setvar "lastpoint" lastp)
pt
)
-
This is one way
(if (not (and pnt (listp pnt) (=(length pnt) 3)))
(options)
)
or like tim said
(if (and pnt (listp pnt))
(do your point stuff)
(options)
)
-
or like tim said
(if (and pnt (listp pnt))
(do your point stuff)
(options)
)
I didn't say it that direct. I forgot all about "listp" Alan. :wink:
I take the credit if you want to give it to me though. :angel:
-
Another...
(defun pt? (pt)
(and (vl-consp pt)
(= (length pt) 3)
(vl-every '(lambda (coord) (= (type coord) 'real)) pt)))
-
That's a good one, Luis.
At the end of the day, I would end up naming the function PointP, but that's just me :)
By the way, could'nt a point be a list of integers also?
-
Yes, it can.
It can also be a 2d point, which is acceptable for most aCAD commands.
-
Perhaps ;
(defun point-p3D (pt)
(and (vl-consp pt)
(= (length pt) 3)
(vl-every '(lambda (coord) 'numberp) pt)
)
)
(setq 3D '(1 2 3))
(setq 2D '(4 5))
(point-p3D 3d )
(point-p3D 2d )
// kwb
-
Abused from another post (http://www.theswamp.org/index.php?topic=7464.msg93380#msg93380) --
(defun IsPoint ( point )
(and
(listp point)
(< 1 (length point) 4)
(vl-every 'numberp point)
)
)
(defun Is3DPoint ( point )
(and
(listp point)
(eq 3 (length point))
(vl-every 'numberp point)
)
)
(vl-every '(lambda (coord) 'numberp) pt)
Hmmm, digesting ...
-
I can't help but wonder if the initial inquiry would be moot if initget were invoked before the getpoint call. Hmmm.
-
(vl-every '(lambda (coord) 'numberp) pt)
Hmmm, digesting ...
yep, supreme redundency :-)
-
Abused from another post (http://www.theswamp.org/index.php?topic=7464.msg93380#msg93380)
I've noticed recently there are a lot of conversations I've forgotten.
-
You're not alone Kerry.
The sleep medication I'm taking is really affecting my memory.
Speaking of such, humour that writes itself: Over supper I was talking to my wife about said memory loss, and said something like "It's a little disconcerting how much the medication is affecting my memory".
She replies: "Really? What have you forgotten?"
<blink.mpg>
<crickets.wav>
-
(clapping-enthusiastic.wav>
-
By the way, could'nt a point be a list of integers also?
Yes...
Even a combination of integers and reals.... there is a better alternative in the post by MP.
I needed reals for that function... no remember why.... [real excuse #23214325423545343256432]