Author Topic: How to delete ExtensionDictionary properly?  (Read 4737 times)

0 Members and 1 Guest are viewing this topic.

bargool

  • Guest
How to delete ExtensionDictionary properly?
« on: December 12, 2011, 07:20:38 AM »
Hello!
I'm removing ExtensionDictionary from DBObject. It removes, that's OK. But drawing needs audit after this action.
Code: [Select]
using (DBDictionary dict = (DBDictionary)o.ExtensionDictionary.GetObject(OpenMode.ForWrite))
{
    if (dict.Count==0)
    {
    dict.Erase();
    }
}
Maybe I have to use another methods?
I found DBObject.Audit method, but cannot understand how to work with it.
This code after dict.Erase() crushes AutoCAD:
Code: [Select]
AuditInfo ai = (AuditInfo)AuditInfo.Create(typeof(AuditInfo), o.UnmanagedObject, true);
dict.Audit(ai);

kaefer

  • Guest
Re: How to delete ExtensionDictionary properly?
« Reply #1 on: December 12, 2011, 10:34:31 AM »
Code: [Select]
using (DBDictionary dict = (DBDictionary)o.ExtensionDictionary.GetObject(OpenMode.ForWrite))
{
    if (dict.Count==0)
    {
    dict.Erase();
    }
}

You're leaving a pointer to an erased object behind. Hark unto the doc, since the doc says:
Quote
DBObject.ReleaseExtensionDictionary Method

Description

Removes the object's extension dictionary (that is, removes the object as the owner of the dictionary object) if it exists and is empty. Once removed, this function calls the dictionary's erase() method. Any reactors attached to the extension dictionary receive normal notification appropriate to an open for write, erase, close sequence

bargool

  • Guest
Re: How to delete ExtensionDictionary properly?
« Reply #2 on: December 12, 2011, 01:54:36 PM »
Thank you!
Code: [Select]
using (DBDictionary dict = (DBDictionary)o.ExtensionDictionary.GetObject(OpenMode.ForRead))
{
  if (dict.Contains(xrecordName))
  {
    dict.UpgradeOpen();
    dict.Remove(xrecordName);
  }
}
o.ReleaseExtensionDictionary();
This code doesn't erase ExtensionDictionary if it has records, and erases if not. That is what I need!

zoltan

  • Guest
Re: How to delete ExtensionDictionary properly?
« Reply #3 on: August 25, 2012, 01:52:43 PM »
Code: [Select]
using (DBDictionary dict = (DBDictionary)o.ExtensionDictionary.GetObject(OpenMode.ForRead))
{
  if (dict.Contains(xrecordName))
  {
    dict.UpgradeOpen();
    dict.Remove(xrecordName);
  }
}
o.ReleaseExtensionDictionary();

Sorry to bring this thread back up from the dead.

Do you need to erase the XRecord after it is removed from the Dictionary?  Or, do XRecords that are not owned by any Dictionary get purged from the database automatically?

Code: [Select]
using (DBDictionary dict = (DBDictionary)o.ExtensionDictionary.GetObject(OpenMode.ForRead))
{
  if (dict.Contains(xrecordName))
  {
    ObjectId xrecordId = dict.GetAt(xrecordName);

    dict.UpgradeOpen();
   
    dict.Remove(xrecordName);

    using (Xrecord xrecord = (XRecord)xrecordId .GetObject(OpenMode.ForWrite))
    {
      xrecord.Erase();
    }
  }
}
o.ReleaseExtensionDictionary();

TheMaster

  • Guest
Re: How to delete ExtensionDictionary properly?
« Reply #4 on: August 25, 2012, 08:12:26 PM »
Code: [Select]
using (DBDictionary dict = (DBDictionary)o.ExtensionDictionary.GetObject(OpenMode.ForRead))
{
  if (dict.Contains(xrecordName))
  {
    dict.UpgradeOpen();
    dict.Remove(xrecordName);
  }
}
o.ReleaseExtensionDictionary();

Sorry to bring this thread back up from the dead.

Do you need to erase the XRecord after it is removed from the Dictionary?  Or, do XRecords that are not owned by any Dictionary get purged from the database automatically?

Code: [Select]
using (DBDictionary dict = (DBDictionary)o.ExtensionDictionary.GetObject(OpenMode.ForRead))
{
  if (dict.Contains(xrecordName))
  {
    ObjectId xrecordId = dict.GetAt(xrecordName);

    dict.UpgradeOpen();
   
    dict.Remove(xrecordName);

    using (Xrecord xrecord = (XRecord)xrecordId .GetObject(OpenMode.ForWrite))
    {
      xrecord.Erase();
    }
  }
}
o.ReleaseExtensionDictionary();


You can erase it if you like, but you don't have to because once its removed from the dictionary, it no longer has an owner which means it will not be saved with the drawing.