Author Topic: Load plug-in at specific points in the startup sequence?  (Read 2801 times)

0 Members and 1 Guest are viewing this topic.

BlackBox

  • King Gator
  • Posts: 3770
Load plug-in at specific points in the startup sequence?
« on: October 25, 2012, 09:14:15 AM »
Is it possible to autoload a .NET plug-in at the end of the startup sequence (without using S::STARTUP via LISP), or using the LispEnded Document Event to instantiate (preferably via registry, LOADCTRLS, etc.)? :?

Using Civil 3D 2011 (.NET 3.5), so the Autoloader mechanism is not an option.

TIA
"How we think determines what we do, and what we do determines what we get."

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Load plug-in at specific points in the startup sequence?
« Reply #1 on: October 25, 2012, 09:28:36 AM »
You could create a lisp command in your acaddoc.lsp that loads the dll before running. If one does not call the new command, the dll is not loaded.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

BlackBox

  • King Gator
  • Posts: 3770
Re: Load plug-in at specific points in the startup sequence?
« Reply #2 on: October 25, 2012, 09:58:24 AM »
Thanks for the reply, Huiz.

I like how the registry allows me to disconnect my plug-in from LISP dependencies, and am just wondering if always loading prior to the startup sequence is the limitation of loading via registry, or if I am simply overlooking something with the bit-coded LOADCTRLS value.
"How we think determines what we do, and what we do determines what we get."

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Load plug-in at specific points in the startup sequence?
« Reply #3 on: October 25, 2012, 10:53:46 AM »
If you set the LOADCTRLS to 4, it will load the dll when you fire the command that is registered to that dll. Is that what you mean?

What is the problem with loading the dll anywhere in the load process?
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

BlackBox

  • King Gator
  • Posts: 3770
Re: Load plug-in at specific points in the startup sequence?
« Reply #4 on: October 25, 2012, 11:01:27 AM »
If you set the LOADCTRLS to 4, it will load the dll when you fire the command that is registered to that dll. Is that what you mean?

What is the problem with loading the dll anywhere in the load process?

Unfortunately, this particular plug-in is an automation only (no CommandMethod), and uses Event handlers to perform the necessary tasks. The plug-in is successful as is.

The only reason I am concerned with the startup sequence is that one of the tasks being performed by this plug-in is to purge registry applications. By nature of executing Initialize() prior to startup being complete, additional unnecessary registry applications are added after the plug-in executes. Now, granted they are removed at the next CommandWillStart callback Method's CommandEventArgs.GlobalCommandName.ToUpper().Contains("SAVE") call.

The only advantage that a LISP call to the -PURGE Command has is when called from AcadDoc.lsp it catches more registry applications that were not yet loaded when the plug-in was loaded. I prefer the .NET method, as it has consistently performed +/-30% faster than the Command call via LISP.
"How we think determines what we do, and what we do determines what we get."

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Load plug-in at specific points in the startup sequence?
« Reply #5 on: October 25, 2012, 11:08:58 AM »
You wouldn't notice a few extra seconds if AutoCAD needs minutes to start ;-)
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

BlackBox

  • King Gator
  • Posts: 3770
Re: Load plug-in at specific points in the startup sequence?
« Reply #6 on: October 25, 2012, 01:00:36 PM »
You wouldn't notice a few extra seconds if AutoCAD needs minutes to start ;-)

I'm not sure that I understand... I'm not concerned with seconds at startup, I'm concerned with startup sequence... Specifically if it is possible to load an assembly from the registry at the end of the startup sequence with no CommandMethod, and no calls from LISP?
"How we think determines what we do, and what we do determines what we get."

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Load plug-in at specific points in the startup sequence?
« Reply #7 on: October 25, 2012, 01:20:11 PM »
I think you're asking the wrong question. I think you should ask how to fix your code so that it doesn't matter when the assembly loads.

BlackBox

  • King Gator
  • Posts: 3770
Re: Load plug-in at specific points in the startup sequence?
« Reply #8 on: October 25, 2012, 01:58:47 PM »
I think you're asking the wrong question. I think you should ask how to fix your code so that it doesn't matter when the assembly loads.

You're absolutely right, Owen.

Since my last post, I've been looking into using other Events that would preclude this from being an issue... Just wanted to do some digging and coding after work before posting back.
"How we think determines what we do, and what we do determines what we get."

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Load plug-in at specific points in the startup sequence?
« Reply #9 on: October 25, 2012, 02:27:33 PM »
Instead of using events, I recommend to define a command, then post the command through the command processor asynchronously so that AutoCAD queues the command for later execution (sorry, I don't know offhand how to do that from managed code, but I'm sure you can figure it out). This is what Autodesk does, and it's the only safe way to execute your code after AutoCAD is completely initialized.

BlackBox

  • King Gator
  • Posts: 3770
Re: Load plug-in at specific points in the startup sequence?
« Reply #10 on: October 25, 2012, 02:54:34 PM »
I will be sure to research your suggestion, as I know full well that I have much to learn.

Perhaps it is my inexperience with .NET showing itself, but I feel that events are a critical part of this particular plug-in, as the entire point if for a small series of tasks to be performed without any user invocation... Both at drawing open, save, and close (when not already done by a preceding save)... Without the benefit of .NET events, I'd simply stay with the basic LISP that has been used for years.
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Load plug-in at specific points in the startup sequence?
« Reply #11 on: October 25, 2012, 05:40:05 PM »
Maybe I am not understanding the question but once added to the registry it will automaticlly load each time at startup, and hook up events in IExtensionApplication.Intialize method.

BlackBox

  • King Gator
  • Posts: 3770
Re: Load plug-in at specific points in the startup sequence?
« Reply #12 on: October 25, 2012, 06:31:07 PM »
Maybe I am not understanding the question but once added to the registry it will automaticlly load each time at startup, and hook up events in IExtensionApplication.Intialize method.

That's exactly what's happening, as I coded it.

Perhaps my problem is in that I've chosen to implement a DocumentCreated event handler, and within each Document also via COmmandWillStart event handler as noted above. There may be another event, rather than DocumentCreated, that will accomplish what I am after in executing toward the end of the startup sequence via Initialize() which can then implement the DocumentCreated event handler thereafter.

Again, the issue is only with the first time run, and not subsequent drawing opens / qnew. Hope that makes more sense.
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Load plug-in at specific points in the startup sequence?
« Reply #13 on: October 25, 2012, 06:50:59 PM »
So you are asking if you can or how to have your dll loaded before AutoCAD creates any documents?
 
Not sure if you can load during start-up when Acad in Zero-document state?
 
 

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Load plug-in at specific points in the startup sequence?
« Reply #14 on: October 26, 2012, 02:10:28 AM »
As far as I understand what you want to do and what Owen purposed, you have to define a command which does the regapp purge and call this command from within the Initialize() method with Document.SendStringtoExecute() which is asynchronous and will execute after the initialisation complete.

Code - C#: [Select]
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Runtime;
  5. using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
  6.  
  7. namespace PurgeRegAppAtStartup
  8. {
  9.     public class StartupPurge : IExtensionApplication
  10.     {
  11.         public void Initialize()
  12.         {
  13.             Document doc = AcAp.DocumentManager.MdiActiveDocument;
  14.             doc.SendStringToExecute("PurgeRegApp\n", false, false, true);
  15.         }
  16.  
  17.         public void Terminate()
  18.         {
  19.         }
  20.  
  21.         [CommandMethod("PurgeRegApp")]
  22.         public void PurgeRegApp()
  23.         {
  24.             Database db = HostApplicationServices.WorkingDatabase;
  25.             using (Transaction tr = db.TransactionManager.StartTransaction())
  26.             {
  27.                 RegAppTable rat = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead);
  28.                 ObjectIdCollection raIds = new ObjectIdCollection();
  29.                 foreach (ObjectId id in rat)
  30.                     raIds.Add(id);
  31.                 db.Purge(raIds);
  32.                 foreach (ObjectId id in raIds)
  33.                 {
  34.                     RegAppTableRecord raptr = (RegAppTableRecord)tr.GetObject(id, OpenMode.ForWrite);
  35.                     raptr.Erase();
  36.                 }
  37.                 tr.Commit();
  38.             }
  39.         }
  40.     }
  41. }
  42.  
Speaking English as a French Frog