Author Topic: Is it safe to use Database in the Initialize() method?  (Read 1776 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Is it safe to use Database in the Initialize() method?
« 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.
« Last Edit: May 15, 2015, 10:00:34 AM by Andrey Bushman »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Is it safe to use Database in the Initialize() method?
« Reply #1 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

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Is it safe to use Database in the Initialize() method?
« Reply #2 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.


Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Is it safe to use Database in the Initialize() method?
« Reply #4 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.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Is it safe to use Database in the Initialize() method?
« Reply #5 on: May 18, 2015, 04:22:40 AM »
Thank you.