Author Topic: Preventing layers, blocks from Purge  (Read 5479 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6144
Preventing layers, blocks from Purge
« on: May 30, 2012, 04:53:55 PM »
I have seen this brought up lately at different sites.
 
Would this be the easiest?
Just create a dictionary in the NOD and store the ObjectIds with HardPointerId code?
Code - C#: [Select]
  1.  [CommandMethod("PurgePrevent")]
  2.         public void PurgePrevent()
  3.         {
  4.             using (Transaction trx = Db.TransactionManager.StartTransaction())
  5.             {
  6.                 List<TypedValue> tvl = new List<TypedValue>();
  7.                 foreach(ObjectId id in Db.LayerTable())
  8.                 {
  9.                 tvl.Add(new TypedValue((int)DxfCode.HardPointerId,id));
  10.                 }
  11.                 foreach (ObjectId id in Db.BlockTable())
  12.                 {
  13.                     tvl.Add(new TypedValue((int)DxfCode.HardPointerId, id));
  14.                 }
  15.                 DBDictionary dic = new DBDictionary();
  16.                 Xrecord xr = new Xrecord();
  17.                 xr.Data = new ResultBuffer(tvl.ToArray());
  18.                 Db.NamedObjectDictionary(OpenMode.ForWrite).SetAt("HideDict", dic);
  19.                 dic.SetAt("Ids", xr);
  20.                 trx.AddNewlyCreatedDBObject(xr, true);
  21.                 trx.AddNewlyCreatedDBObject(dic, true);
  22.                 dic.TreatElementsAsHard = true;  
  23.        
  24.                 trx.Commit();
  25.             }
  26.         }
  27.  
  28.  
« Last Edit: May 31, 2012, 03:50:44 PM by Jeff H »

TheMaster

  • Guest
Re: Preventing layers, blocks from Purge
« Reply #1 on: May 30, 2012, 07:16:14 PM »
I have seen this brought up lately at different site.
 
Would this be the easiest?
Just create a dictionary in the NOD and store the ObjectIds with HardPointerId code?
Code - C#: [Select]
  1.  [CommandMethod("PurgePrevent")]
  2.         public void PurgePrevent()
  3.         {
  4.             using (Transaction trx = Db.TransactionManager.StartTransaction())
  5.             {
  6.                 List<TypedValue> tvl = new List<TypedValue>();
  7.                 foreach(ObjectId id in Db.LayerTable())
  8.                 {
  9.                 tvl.Add(new TypedValue((int)DxfCode.HardPointerId,id));
  10.                 }
  11.                 foreach (ObjectId id in Db.BlockTable())
  12.                 {
  13.                     tvl.Add(new TypedValue((int)DxfCode.HardPointerId, id));
  14.                 }
  15.                 DBDictionary dic = new DBDictionary();
  16.                 Xrecord xr = new Xrecord();
  17.                 xr.Data = new ResultBuffer(tvl.ToArray());
  18.                 Db.NamedObjectDictionary(OpenMode.ForWrite).SetAt("HideDict", dic);
  19.                 dic.SetAt("Ids", xr);
  20.                 trx.AddNewlyCreatedDBObject(xr, true);
  21.                 trx.AddNewlyCreatedDBObject(dic, true);
  22.                 dic.TreatElementsAsHard = true;  
  23.        
  24.                 trx.Commit();
  25.             }
  26.         }
  27.  
  28.  

Have you tried it?

If it works, I would put the references to the objects in their owner's extension dictionary rather than the NOD

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Preventing layers, blocks from Purge
« Reply #2 on: May 30, 2012, 08:17:13 PM »
The little bit of testing it does.

zoltan

  • Guest
Re: Preventing layers, blocks from Purge
« Reply #3 on: May 31, 2012, 07:47:58 AM »
Unless something has changed, I have discovered in the past that this does not prevent the automatic purging of unreferenced anonymous blocks.

Can you confirm this?

TheMaster

  • Guest
Re: Preventing layers, blocks from Purge
« Reply #4 on: May 31, 2012, 11:06:54 AM »
Unless something has changed, I have discovered in the past that this does not prevent the automatic purging of unreferenced anonymous blocks.

Can you confirm this?

I'm pretty sure that unreferenced anonymous blocks are handled in the same way as erased objects. They're not purged in the same way that other objects are (for example, by the purge command).  They are simply ignored when the database is subsequently opened, and hence, are not saved with it.

I'm also assuming that the OP wants to prevent the user from purging items, verses AutoCAD removing them because they're not referenced.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Preventing layers, blocks from Purge
« Reply #5 on: May 31, 2012, 03:29:50 PM »
Unless something has changed, I have discovered in the past that this does not prevent the automatic purging of unreferenced anonymous blocks.

Can you confirm this?

Have not tested for that and was just seeing if it worked, I personally have no need for it.
« Last Edit: May 31, 2012, 03:34:17 PM by Jeff H »

exmachina

  • Guest

toberino

  • Guest
Re: Preventing layers, blocks from Purge
« Reply #7 on: June 01, 2012, 10:16:16 AM »
I have seen this brought up lately at different sites.
 
Would this be the easiest?
Just create a dictionary in the NOD and store the ObjectIds with HardPointerId code?
Code - C#: [Select]
  1.  [CommandMethod("PurgePrevent")]
  2.         public void PurgePrevent()
  3.         {
  4.             using (Transaction trx = Db.TransactionManager.StartTransaction())
  5.             {
  6.                 List<TypedValue> tvl = new List<TypedValue>();
  7.                 foreach(ObjectId id in Db.LayerTable())
  8.                 {
  9.                 tvl.Add(new TypedValue((int)DxfCode.HardPointerId,id));
  10.                 }
  11.                 foreach (ObjectId id in Db.BlockTable())
  12.                 {
  13.                     tvl.Add(new TypedValue((int)DxfCode.HardPointerId, id));
  14.                 }
  15.                 DBDictionary dic = new DBDictionary();
  16.                 Xrecord xr = new Xrecord();
  17.                 xr.Data = new ResultBuffer(tvl.ToArray());
  18.                 Db.NamedObjectDictionary(OpenMode.ForWrite).SetAt("HideDict", dic);
  19.                 dic.SetAt("Ids", xr);
  20.                 trx.AddNewlyCreatedDBObject(xr, true);
  21.                 trx.AddNewlyCreatedDBObject(dic, true);
  22.                 dic.TreatElementsAsHard = true;  
  23.        
  24.                 trx.Commit();
  25.             }
  26.         }
  27.  
  28.  

Hey Jeff, thanks for the help with this, but this is a little above my head. I am not sure how to apply this code. I have not tried lisp yet, but it doesn't quite look like lisp. I'll give it a test here in a little bit, I have a lot to do today. Or, if you could give me a little more direction that would be great.