Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to determine is entity exists by handle.

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
mid-awe
864 Views, 3 Replies

How to determine is entity exists by handle.

Hi all,

 

I have a specific need to determine if an entity is existing or not so that I can either make changes to or create the entity.

 

I'm trying to do this while referring to the entity by it's handle. Below is my code this far but it doesn't work.

 

(IF (AND (SETQ HNDL (VLAX-LDATA-GET "TB" (STRCAT PLN "PLAN")))
	 (NOT (VLAX-ERASED-P (VLAX-ENAME->VLA-OBJECT (HANDENT HNDL))))
    )
  (PROGN
    ;;| DO SOMETHING WITH THE EXISTING ENTITY 
  )
  (PROGN
    ;;| MAKE THE ENTITY 
(vlax-ldata-put "TB" (strcat PLN "PLAN") (CDR (ASSOC 5 (entget (entlast))))) ) )

 I ran the program and the handle was stored, then I deleted the entity and ran the code again and this is the error I get:

; error: unable to get ObjectID: nil

 

This VLISP stuff sometime has unpredictable hoops to jump through first, so I wondering if this is the case here. Am I missing something? Or, maybe there is another way?

 

Thank you.

3 REPLIES 3
Message 2 of 4
Lee_Mac
in reply to: mid-awe

The error you receive is a result of supplying the vlax-erased-p function with a null argument, since the vlax-ename->vla-object function will return nil if the supplied entity is erased - this information alone should indicate the required test for your if statement.

 

Alternatively, you can use the entget function to test for the erase flag, since this function will also return nil if the supplied entity argument is erased, e.g.:

 

(if
    (and
        (setq han (vlax-ldata-get "TB" (strcat pln "PLAN")))
        (setq ent (handent han))
        (entget ent)
    )
    (progn
        ;; Do something with entity 'ent'
    )
    (progn
        ;; Make the entity
    )
)
Message 3 of 4
mid-awe
in reply to: Lee_Mac

Thank you Lee. I had hoped that it'd be something simple as that.
Message 4 of 4
Lee_Mac
in reply to: mid-awe

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost