Author Topic: Check if ename or object  (Read 1145 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
Check if ename or object
« on: December 29, 2016, 03:22:31 AM »
Is it possible to check if a variable is an entity-name or object ?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2139
  • class keyThumper<T>:ILazy<T>
Re: Check if ename or object
« Reply #1 on: December 29, 2016, 03:48:16 AM »
Yes
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2139
  • class keyThumper<T>:ILazy<T>
Re: Check if ename or object
« Reply #2 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)
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2139
  • class keyThumper<T>:ILazy<T>
Re: Check if ename or object
« Reply #3 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.  
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Check if ename or object
« Reply #4 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.  
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Check if ename or object
« Reply #5 on: December 29, 2016, 11:36:06 PM »
Thanks to all.