How to check whether entity
Hi all,I am getting error: bad argument type: lentityp by running following code:
(defun ATR ( handSTR)(if (HANDENT handSTR) (progn (setq ss1 (ssadd handSTR)) (command ".attedit" "y" "*" "*" "*" ss1 "color" "t" "255,0,0" "n") (ssdel handSTR ss1) ) ) (princ))(ATR "543B")
What am I doing wrong here? _$ (handent nil)Error: bad argument type: stringp nil_1$
So use:
(and (eq 'STR (type handent)) (handent handSTR))
instead of:
(HANDENT handSTR)
EDIT: Oh, and the actual reason for the error:
Change:
(setq ss1 (ssadd handSTR))
To:
(setq ss1 (ssadd (handent handSTR))) I would also suggest testing whether (entget (handent )) returns a non-nil value (i.e. testing whether the entity is erased), as handent can return the entity name for entities for which the erase flag is set. ... Or use vlax-erased-p (faster than entget). I also think that it would be good to include this part to the checklist (wrapped within and function):
(setq ss1 (ssadd (handent handSTR)))
And use progn for the command call and ssdel.
To account non-graphical entity's handles:
_$ (ssadd (handent (cdr (assoc 5 (entget (namedobjdict))))))nil
@Grrr:
(equal (namedobjdict) (handent (cdr (assoc 5 (entget (namedobjdict)))))) => T
I can't think of a scenario where I would want to add a non-graphical entity to a selection set.
Overthinking.
We don't know how the OP collects the handles - so thats just small additional check, not a big deal and will evaluate anyways (with or without checking). Thanks all for your kind help.
Problem resolved.
页:
[1]