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

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 4707
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 »

TT

  • Swamp Rat
  • Posts: 826
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: 4707
Re: Preventing layers, blocks from Purge
« Reply #2 on: May 30, 2012, 08:17:13 pm »
The little bit of testing it does.

zoltan

  • Newt
  • Posts: 186
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?

TT

  • Swamp Rat
  • Posts: 826
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: 4707
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 »

jar

  • Bull Frog
  • Posts: 305
Intel Core i7-3820 | 32GB RAM @ 1600MHz | 2 x 512GB SSD 6Gb/s | nVidia GeForce GTX 680M | Windows 7 Pro x64 | Bricscad v14 x64 | Visual Studio 2008 Pro | A fridge with a lot of beer | A lot of cigarettes (Gauloises and Ducados)

toberino

  • Mosquito
  • Posts: 10
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.