Search code examples
c#wpfmvvmautocad-plugin

autocad .net storing and retrieving object Id without using ObjectId


I am working on a autoCAD .net project in which I create a MVVM pattern to select and modify an entity. I want to store the selected entity 's info/values into the view model, change the info/values (through the WPF UI that pops up and through my code as well) then apply the changes to the entity.

The problem is: if I want to apply the changes to the entity, I have to know "which" entity will receive the changes. Thus, I want to store the entity ObjectId and retrieve it later WITHOUT using ObjectId struct from acdbmgd.dll of AutoCAD since that will make my UI project depends on a specific version of AutoCAD (Yes, it is a REQUIREMENT that my UI project works on .net framework alone).

Is there any way I can do this? I intend to store the objectId in an object then cast it back to objecId but it didn't work. Please help. Thank you very much.


Solution

  • As you may or may not know, every entity in a drawing can be retrieved in 3 unique ways: ObjectID, Handle and an Instance Pointer. Object ids are created for each entity each time the drawing database is opened, thus they are only unique until the current drawing is closed. Once it is reopened, all ObjectIDs will be completely different. Handles, however, persist between sessions and, as mavious stated, can be converted to a long and back. Not sure if you care to keep the reference to entities between sessions, but this at least solves your data type issue. Believe me, I completely understand your desire to keep autodesk separate from your main assembly. This post will have all the information that you may need.