bababarghi 发表于 2022-7-5 16:26:07

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?

Grrr 发表于 2022-7-5 16:39:23

_$ (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)))

Lee Mac 发表于 2022-7-5 16:47:31

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.

Roy_043 发表于 2022-7-5 16:55:59

... Or use vlax-erased-p (faster than entget).

Grrr 发表于 2022-7-5 17:05:46

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
 

Roy_043 发表于 2022-7-5 17:13:57

@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.

Grrr 发表于 2022-7-5 17:26:05

 
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).

bababarghi 发表于 2022-7-5 17:31:30

Thanks all for your kind help.
 
Problem resolved.
页: [1]
查看完整版本: How to check whether entity�