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.
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
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 ) )