TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on December 29, 2016, 03:22:31 AM

Title: Check if ename or object
Post by: mailmaverick on December 29, 2016, 03:22:31 AM
Is it possible to check if a variable is an entity-name or object ?
Title: Re: Check if ename or object
Post by: kdub_nz on December 29, 2016, 03:48:16 AM
Yes
Title: Re: Check if ename or object
Post by: kdub_nz on December 29, 2016, 04:01:15 AM
Have a play ...

Code - Auto/Visual Lisp: [Select]
  1. (setq acadObj (vlax-get-acad-object)) ;;-> #<VLA-OBJECT IAcadApplication 00007ff7bf137538>
  2.  
  3. (type acadObj) ;;-> VLA-OBJECT
  4.  
  5. (= (type acadObj) 'VLA-OBJECT)
  6.  
  7.  
  8. (setq ename (cdar (entget (entlast))) ) ;;-><Entity name: 158e8ba9460>
  9.  
  10. (type ename) ;;-> ENAME
  11.  
  12. (= (type ename) 'ENAME)
Title: Re: Check if ename or object
Post by: kdub_nz on December 29, 2016, 04:11:55 AM
Realised I had these in my Library
May help you ..

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;; (KDUB:emptystring-p "1") ->nil
  3. ;; (KDUB:emptystring-p "") ->T
  4. ;; (KDUB:emptystring-p " ") ->T
  5. ;;
  6. ;; (KDUB:notemptystring-p "x") -> T
  7. ;; (KDUB:notemptystring-p "") -> nil
  8. ;; (KDUB:notemptystring-p " ") -> nil
  9. ;;
  10. ;; (KDUB:validstring-p "x") -> T
  11. ;; (KDUB:validstring-p "") -> nil
  12. ;; (KDUB:validstring-p " ") -> T
  13. (defun kdub:string-p (arg) (= (type arg) 'str))
  14. (defun kdub:validstring-p (arg) (and (= (type arg) 'str) (/= 0 (strlen arg))))
  15. (defun kdub:emptystring-p (arg)
  16.   (and (= (type arg) 'str) (= 0 (strlen (vl-string-trim " " arg))))
  17. )
  18. (defun kdub:notEmptystring-p (arg)
  19.   (and (= (type arg) 'str) (/= 0 (strlen (vl-string-trim " " arg))))
  20. )
  21. (defun kdub:real-p (arg) (equal (type arg) 'real))
  22. (defun kdub:integer-p (arg) (equal (type arg) 'int))
  23. (defun kdub:vlaobject-p (arg) (equal (type arg) 'vla-object))
  24. (defun kdub:ename-p (arg) (equal (type arg) 'ename))
  25. (defun kdub:variant-p (arg) (equal (type arg) 'variant))
  26.  
  27.  
  28.  
Title: Re: Check if ename or object
Post by: Grrr1337 on December 29, 2016, 06:18:52 AM
Or if you have the handle, then you could simply convert it to an ename or vla-object:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq handle (cdr (assoc 5 (entget (car (entsel))))))
  2. "24B"
  3. _$ (handent handle)
  4. <Entity name: 7ff662504cb0>
  5. #<VLA-OBJECT IAcadLWPolyline 000000623f71d378>
  6. _$
  7.  
Title: Re: Check if ename or object
Post by: mailmaverick on December 29, 2016, 11:36:06 PM
Thanks to all.