Jump to content

How to check whether entity's handle is valid?


Recommended Posts

Posted

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?

Posted

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

Posted

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.

Posted

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

Posted

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 

 

;)

Posted

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

Posted
@Grrr:

(equal (namedobjdict) (handent (cdr (assoc 5 (entget (namedobjdict)))))) => T

 

Overthinking. :oops:

 

I can't think of a scenario where I would want to add a non-graphical entity to a selection set.

 

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

Posted

Thanks all for your kind help.

 

Problem resolved.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...