TheSwamp

Code Red => .NET => Topic started by: Andrey Bushman on May 15, 2015, 09:56:04 AM

Title: Is it safe to use Database in the Initialize() method?
Post by: Andrey Bushman on May 15, 2015, 09:56:04 AM
When I do it, then my code looks something like this:
Code - C#: [Select]
  1. public void Initialize() {
  2.   Document doc = cad.DocumentManager.MdiActiveDocument;
  3.   if (null == doc)
  4.     return;
  5.  
  6.   Database db = doc.Database;
  7.   Editor ed = doc.Editor;
  8.  
  9.   using (doc.LockDocument()) {
  10.     using (Transaction tr = db.TransactionManager.StartTransaction()) {
  11.       ed.WriteMessage("\nThe \"{0}\" assembly successfully loaded.\n",
  12.         this.GetType().Assembly.Location);      
  13.       // TODO: Here is my code of working with Database...
  14.       tr.Commit();
  15.     }
  16.   }
  17. }
Assembly can be registered for autoloading (through the registry record or BUNDLE engine). I hadn't problems with such approach, but I remember - Alexander Rivilis wrote he had. He wrote what the Document (or Database) can be initialized not completely at the time of operation of this code. Ok, how can I check initialization of these objects was finished?

P.S. The "Spell Chek" button in the edition mode doesn't work, I see an empty window.
Title: Re: Is it safe to use Database in the Initialize() method?
Post by: Jeff H on May 15, 2015, 10:11:23 AM
I do mine in a static constructor of class with PerDocData attribute and not had a problem
Title: Re: Is it safe to use Database in the Initialize() method?
Post by: Andrey Bushman on May 15, 2015, 10:15:14 AM
PerDocData attribute
What is it? I can't find info about it in ObjectARX SDK and MSDN.
Title: Re: Is it safe to use Database in the Initialize() method?
Post by: Jeff H on May 15, 2015, 11:03:40 AM
Sorry the PerDocumentClass Attribute

http://through-the-interface.typepad.com/through_the_interface/2014/04/per-document-data-in-autocad-net-applications-part-4.html
Title: Re: Is it safe to use Database in the Initialize() method?
Post by: Alexander Rivilis on May 15, 2015, 11:04:53 AM
PerDocData attribute
What is it? I can't find info about it in ObjectARX SDK and MSDN.
Kean Walmsley wrote about it: http://through-the-interface.typepad.com/through_the_interface/2014/04/per-document-data-in-autocad-net-applications-part-4.html
But this attribute was introduced only in AutoCAD 2015.
Title: Re: Is it safe to use Database in the Initialize() method?
Post by: Andrey Bushman on May 18, 2015, 04:22:40 AM
Thank you.