In my previous post I described how you could use the Autodesk.AutoCAD.Runtime.IExtensionApplication interface to implement initialization code in your .NET module. Building on this, we're now going to look at how use of the Autodesk.AutoCAD.Runtime.IExtensionApplication interface can also allow you - with very little effort - to optimize the architecture of your managed modules for faster loading into AutoCAD.
First some information from the "Using .NET for AutoCAD documentation" (which is available in the ObjectARX Developer's Guide on the ObjectARX SDK):
When AutoCAD loads a managed application, it queries the application's assembly for an ExtensionApplication custom attribute. If this attribute is found, AutoCAD sets the attribute's associated type as the application's entry point. If no such attribute is found, AutoCAD searches all exported types for an IExtensionApplication implementation. If no implementation is found, AutoCAD simply skips the application-specific initialization step.
In addition to searching for an IExtensionApplication implementation, AutoCAD queries the application's assembly for one or more CommandClass attributes. If instances of this attribute are found, AutoCAD searches only their associated types for command methods. Otherwise, it searches all exported types.
The samples that I've shown in this blog - and most of those on the ObjectARX SDK - do not show how you can use the ExtensionApplication or CommandClass attribute in your code, as it's not essential to implement them for your application to work. But if you have a large .NET module to be loaded into AutoCAD, it might take some time for AutoCAD to check the various objects in the assembly, to find out which is the ExtensionApplication and which are the various CommandClasses.
The attributes you need to implement are very straightforward:
These assembly-level attributes simply tell AutoCAD where to look for the various objects it will otherwise need to identify by searching. Here's some more information from the documentation on the use of these attributes:
The ExtensionApplication attribute can be attached to only one type. The type to which it is attached must implement the IExtensionApplication interface.
A CommandClass attribute may be declared for any type that defines AutoCAD command handlers. If an application uses the CommandClass attribute, it must declare an instance of this attribute for every type that contains an AutoCAD command handler method.
While optimizing yesterday's code to reduce load-time, I also changed the structure slightly to be more logical. The above attributes also take classes within a namespace, so I decided to split the initialization code (the "Initialization" class) away from the command implementations (the "Commands" class), but keeping them both in the same ("ManagedApplication") namespace.
And here's the code...
public class Initialization
public void Initialize()
Editor ed =
ed.WriteMessage("Initializing - do something useful.");
public void Terminate()
public class Commands
public void Test()
Editor ed =
ed.WriteMessage("This is the TST command.");
Public Class Initialization
Public Sub Initialize() Implements _
Dim ed As Editor = _
ed.WriteMessage("Initializing - do something useful.")
Public Sub Terminate() Implements _
Public Class Commands
Public Sub Test()
Dim ed As Editor = _
ed.WriteMessage("This is the TST command.")