Author Topic: How to fast-check the Var is Point?  (Read 369 times)

0 Members and 1 Guest are viewing this topic.

d2010

  • Newt
  • Posts: 169
How to fast-check the Var is Point?
« on: April 28, 2021, 03:57:42 PM »
I need the new-function "if_ispoint" with  small-size?>.
I wrote this source, because many times, i want fix the point.error/s automatically, and always "if_ispoint" repair internal-bugs-inside.Var.
Code: [Select]
(setq ag (if_ispoint a170 (getvar "VIEWCTR")))
:whistling:
Code: [Select]
(defun if_ispoint(f163 elseways / $rp zfs lcd led lev noz noy nox)     
  (setq;|a27304|;
lcd (quote LIST)
led (quote REAL)
lev (quote INT)
zfs RTREJ) (if (and  (=  (type f163) lcd) (/= f163 nil)) (setq;|a27424|;
zfs (length f163))) (setq;|a27448|;
retl elseways) (setq;|a27468|;
noy nil
noz (if (>  zfs 2) (type (caddr f163)) nil)) (if (and  (>  zfs 2) (or (=  noz lev) (=  noz led))) (setq;|a27588|;
noy (type (cadr f163))
noy (or (=  noy lev) (=  noy led)))) (if (=  zfs 2) (setq;|a27682|;
noy (type (cadr f163))
noy (or (=  noy lev) (=  noy led)))) (setq;|a27756|;
nox nil) (if noy (setq;|a27784|;
nox (type (car f163))
nox (or (=  nox lev) (=  nox led)))) (setq;|a27858|;
$rp elseways) (if nox (setq;|a27882|;
$rp (cond ( (>  zfs 2) (list (car f163) (cadr f163) (caddr f163)))( (list (car f163) (cadr f163) 0.0)))))
$rp)


How to check the variabile is Point?
« Last Edit: May 03, 2021, 10:51:15 AM by d2010 »

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9624
Re: How to fast-check the Var is Point?
« Reply #1 on: April 28, 2021, 06:22:18 PM »
My Autolisp is very rusty but it seems to me that all you are really doing in the above code is verifying that you are dealing with a list and the z-value is 0. So wouldn't something like the following be "easier"? I agree, mine isn't very "safe"--in that you can supply only one point list and get a funky point list return--but the point is, this is small and an extremely fast "flattener" function that seems to do almost the same.

Code - Auto/Visual Lisp: [Select]
  1. (defun flatten_pt (x)
  2.   (if (atom x)
  3.    (float x)
  4.    (list (flatten_pt (car x))
  5.          (flatten_pt (cadr x))
  6.          0.0 )) )
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12488
  • London, England
Re: How to fast-check the Var is Point?
« Reply #2 on: April 29, 2021, 08:30:10 AM »
Assuming that you're trying to verify whether or not a supplied value represents a 2D/3D point, I would suggest the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun point-p ( x )
  2.     (and (listp x)
  3.          (< 1 (vl-list-length x) 4)
  4.          (vl-every 'numberp x)
  5.     )
  6. )

d2010

  • Newt
  • Posts: 169
Re: How to fast-check the Var is Point?
« Reply #3 on: May 04, 2021, 05:31:44 AM »
Thank you,Lee Mac , Now I can fix-automatically point-problems.

In My programe.lsp, Now I  can autofix-point-var-automatically.
I replace allfailed with (getvar "VIEWCTR").
Code: [Select]

_$ (vl-load-com)
_$ (setq a1 (if_ispoint (getpoint) nil))
(27.54 25.6945 0.0)
_$ (setq a1 (if_ispoint (getpoint) nil))
; error: Function cancelled
_$ (setq a1 (if_ispoint "(getpoint)" (getvar "VIEWCTR")))
(50.0 50.0 0 0.0)
:tickedoff:

Code - Auto/Visual Lisp: [Select]
  1. (setq RTCAN -5003)
  2. (defun if_ispoint(f163 allfailed / $rr cnt nop)    
  3.   (setq
  4.          $rr allfailed
  5.          nop (read "NUMBERP")
  6.          cnt (if (and (/= f163 nil) (listp f163)) (length f163) RTCAN)) (if (and (=  cnt 2) (vl-every nop f163)) (setq
  7.          $rr (append f163 (list 0.0))) (if (and (=  cnt 3) (vl-every nop f163)) (setq
  8.          $rr f163)))
  9. $rr)
  10.  


« Last Edit: May 04, 2021, 05:37:08 AM by d2010 »