Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
JEdwardL
Posts: 67
Registered: ‎03-02-2004
Message 1 of 3 (212 Views)

Convert ObjectID to Handle

212 Views, 2 Replies
01-10-2012 02:44 PM

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

 

 

*Expert Elite*
Lee_Mac
Posts: 1,178
Registered: ‎12-29-2009
Message 2 of 3 (211 Views)

Re: Convert ObjectID to Handle

01-10-2012 03:09 PM in reply to: JEdwardL
(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>) ]

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Mentor
stevor
Posts: 853
Registered: ‎12-26-2005
Message 3 of 3 (184 Views)

Re: Convert ObjectID to Handle

01-11-2012 08:26 AM in reply to: JEdwardL

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.

 

S
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.