It looks like I might have programmed myself into a corner again!
I wrote code for an application that stores links to lines and blocks in dictionaries using handles. The routines work well and I can manipulate the data marvelously, but if one of the lines or blocks get erased the whole danged opera falls apart. I knew this when I wrote the routines and have always been careful about using the ERASE command, as a matter of fact, I considered disabling it.
I am trying to make the package more robust. I have been experimenting with attaching a reactor (:vlr-erased) to the objects which fires when the object is erased. Unfortunately it fires before I can retrieve the handle of the object so that I can remove the references from the dictionaries. The only thing that I can retrieve once ERASE fires is the ObjectID. I can't seem to find a Visual Lisp routine to convert this value to a handle, does one exist? Is there an ObjectID collection that has any references in it?
I found several threads on the subject in different discussion groups, but none offered any acceptable solutions.
Thank you for any help you can give.
J Leavitt
(defun IDtoHandle ( doc id ) (vla-get-handle (vla-objectidtoobject doc id)) )
Though, although I haven't seen the application, I have a distinct feeling that you are over complicating things - surely you can just add some error trapping in the form of a conditional testing whether an object / entity has been erased? [vlax-erased-p / (entget <entity>) ]
Applying LeeMac's method:
(if (entget entname )
(progn ; do your thing
Or, with other tests:
(if (and entname (entget entname)
... other tests
)
(progn ...
Done all the time for previously selected or named objects.
Also, sometimes the data type of the variable 'entname,'
or whatever variable name used,
must be differentiated between 'ENAME and 'VLA-OBJECT.