Author Topic: erased objects in database  (Read 2210 times)

0 Members and 1 Guest are viewing this topic.

nekitip

  • Guest
erased objects in database
« on: July 30, 2012, 01:44:30 PM »
Hello, I have a simple question about erased objects.

When entity is erased, it is still in database, only marked erased. It remains there until its database is destroyed (by closing document), and then fires event goodbye. It can be reach with transaction by knowing objectid and third parameter set to True. Right?
Code - vb.net: [Select]
  1.  Dim obj As DBObject = trans.GetObject(oid, OpenMode.ForRead, True)

And the question is:
is there any scenario where erased entity will be permanently removed before database is destroyed?

owenwengerd

  • Bull Frog
  • Posts: 451
Re: erased objects in database
« Reply #1 on: July 30, 2012, 02:48:36 PM »
Right. Yes, there are several scenarios where an entity (erased or otherwise) can be destroyed before its owning database is destroyed. The most obvious case is when it is replaced with a different object (via AcDbObject::handOverTo), which results in the database relinquishing ownership of the original object.

nekitip

  • Guest
Re: erased objects in database
« Reply #2 on: August 01, 2012, 02:45:37 AM »
So if objectid gets disconnected from the entity, then can we at least be sure that "goodbye" will always be fired?
As Tony would say, an another of my "vague" description :)

Here is what bothers me actually.
Let's say i have an entity, a line in autocad. But in my program, it is not just a line, it is, for example "UTP CAT 5 cable". I write that string in xrecord of entity. When file is closed/opened, I want to read that string (and with other stuff) so I know that line is indeed mine and what it represents. That will most likely work.
But I want that when user stretches line, my program to be updated with new distance, so i hook to entitys "modified" event. That also will most likely work.

But, what to do when user deletes entity? If I unhook events at that moment, I will not be informed that it has been unerased once the user runs "undo" command. If I keep it connected then, you say - I cannot keep it forever in that state, because, you say - eventually they will be destroyed sometime?

What is a common practice to this problem?

owenwengerd

  • Bull Frog
  • Posts: 451
Re: erased objects in database
« Reply #3 on: August 01, 2012, 10:14:44 AM »
Synchronizing drawing file content with external data is a complicated and much different topic that has very little to do with erased objects, so I recommend to start a new thread on that topic. The bottom line, though, is that you have to design the entire ecosystem around the requirements and limitations of the various pieces, and a piecemeal approach of solving small problems like how to handle unerased or reappended entitities is never going to get you across the finish line.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: erased objects in database
« Reply #4 on: August 01, 2012, 01:05:10 PM »
Sounds like you should be using an overrule for your objects instead of the way your trying to do it.  That way you would know if the object was being modified or deleted and the object itself could perform the appropriate action.
Revit 2019, AMEP 2019 64bit Win 10

TheMaster

  • Guest
Re: erased objects in database
« Reply #5 on: August 01, 2012, 07:55:34 PM »
So if objectid gets disconnected from the entity, then can we at least be sure that "goodbye" will always be fired?
As Tony would say, an another of my "vague" description :)

Here is what bothers me actually.
Let's say i have an entity, a line in autocad. But in my program, it is not just a line, it is, for example "UTP CAT 5 cable". I write that string in xrecord of entity. When file is closed/opened, I want to read that string (and with other stuff) so I know that line is indeed mine and what it represents. That will most likely work.
But I want that when user stretches line, my program to be updated with new distance, so i hook to entitys "modified" event. That also will most likely work.

But, what to do when user deletes entity? If I unhook events at that moment, I will not be informed that it has been unerased once the user runs "undo" command. If I keep it connected then, you say - I cannot keep it forever in that state, because, you say - eventually they will be destroyed sometime?

What is a common practice to this problem?

A common practice is to avoid trying to keep data attached to AutoCAD entities synchronized with replicated data in an external data store.

Instead, while a drawing is open, you should access the data in the drawing directly when needed.  If you persist the data in some other form besides in the drawing, you can update that external data when the drawing file is saved.