マネージ アプリケーションは、 オプションの Autodesk.AutoCAD.Runtime.IExtensionApplication インタフェースを実装することによって初期化タスクや終了タスクを実行することを選択できます。
Autodesk.AutoCAD.Runtime.IExtensionApplication インタフェースは、Initialize() メソッドと Terminate() メソッドを提供します。マネージ アプリケーションは手動でアンロードできないため、AutoCAD プログラムを閉じると、Terminate() メソッドのいずれかの実装が呼び出されます。
アプリケーションが多数のデータ タイプを定義する場合、IExtensionApplication を実装し、2 つのオプションのカスタム属性を使用することによって、ロード時のパフォーマンスを最適化することができます。これらの属性(ExtensionApplication と CommandClass)は、AutoCAD プログラムがアプリケーションの初期化ルーチンとコマンド ハンドラを見つけるのを手助けします。
マネージ アプリケーションはどれでも、これらの属性を使用することができます。ただし、その最適化の効果は、大きいアプリケーションでのみ測定可能です。
AutoCAD プログラムは、マネージ アプリケーションをロードするとき、アプリケーションのアセンブリで ExtensionApplication 属性を照会します。この属性が見つかった場合、AutoCAD プログラムはこの属性に関連付けられたタイプをアプリケーションのエントリ ポイントとして設定します。このような属性が見つからない場合、AutoCAD はすべてのエクスポートされたタイプで IExtensionApplication 実装を検索します。実装が見つからない場合、AutoCAD プログラムはアプリケーション固有の初期化手順をスキップします。
ExtensionApplication 属性は、1 つのタイプにのみにアタッチすることができます。属性がアタッチされているタイプは、IExtensionApplication インタフェースを実装する必要があります。
AutoCAD プログラムは、アプリケーションで IExtensionApplication の実装を検索するだけでなく、アプリケーションのアセンブリで 1 つまたは複数の CommandClass 属性を照会します。この属性のインスタンスが見つかると、AutoCAD プログラムはコマンド メソッドで関連付けられたタイプのみを検索します。その他の場合、すべてのエクスポートされたタイプを検索します。
CommandClass 属性は、AutoCAD コマンド ハンドラを定義するすべてのタイプに対して宣言できます。アプリケーションが、CommandClass 属性を使用する場合、AutoCAD コマンド ハンドラ メソッドを含むすべてのタイプに対してこの属性のインスタンスを宣言する必要があります。
次の操作では、これらの属性の使用方法を説明します。
初期化タスクまたは終了タスクを実行する必要がない場合は、インタフェース メソッドの空の実装を提供します。
... Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Interop Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <Assembly: ExtensionApplication(GetType(HelloWorld.HelloWorldApp))> <Assembly: CommandClass(GetType(HelloWorldCommands))> Namespace HelloWorld Public Class HelloWorldApp Implements Autodesk.AutoCAD.Runtime.IExtensionApplication ... End Class Public Class HelloWorldCommands ' Defines a command that prompts a message on the AutoCAD ' command line. <Autodesk.AutoCAD.Runtime.CommandMethod("HELLO")> Public Sub HelloCommand() ... End Sub End Class End Namespace
... using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Interop; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [assembly: ExtensionApplication(typeof(HelloWorld.HelloWorldApp))] [assembly: CommandClass(typeof(HelloWorld.HelloWorldCommands))] namespace HelloWorld { public class HelloWorldApp : Autodesk.AutoCAD.Runtime.IExtensionApplication { ... } public class HelloWorldCommands { // Defines a command that prompts a message on the AutoCAD // command line. [CommandMethod("HELLO")] public void HelloCommand() { ... } } }