优化CAD中 .NET加载程序

      
     在CAD中提供了Autodesk.AutoCAD.Runtime.IExtensionApplication界面执行初始化代码模块。我们现在要考虑如何利用Autodesk.AutoCAD.Runtime.IExtensionApplication接口,让我们的模块以,更快的加载到AutoCAD的。
 
  • 在AutoCAD中加载一个托管应用程序,查询应用程序集的ExtensionApplication自定义属性。如果此属性被发现, AutoCAD中设置属性的相关类型的应用程序的入口点。如果没有这样的属性发现,自动搜索所有类型的出口IExtensionApplication执行。如果没有执行发现, AutoCAD的只是跳过特定应用的初始化步骤。
  • 除了寻找一种IExtensionApplication执行, AutoCAD的查询应用程序的大会的一个或多个CommandClass属性。如果此属性的实例发现,自动搜索只及其相关类型的指挥方法。否则,搜索所有出口类型。
如何使用ExtensionApplication或CommandClass属性在您的代码中,因为它不是必须的。但是,如果你有一个大的。 NET模块加载到AutoCAD中,它可能需要一些时间来检查AutoCAD中的各种物体在应用程序上,找出是ExtensionApplication并在各CommandClasses 。

C#:

[assembly: ExtensionApplication(typeof(InitClass))]

[assembly: CommandClass(typeof(CmdClass))]

这些大会级别属性只是告诉AutoCAD的情况下寻找各种物体将其他需要查明的搜索。下面是一些详细信息的文件,在使用这些属性:
 
该ExtensionApplication属性可以附加只有一个类型。类型其所附着必须执行IExtensionApplication接口。
阿CommandClass属性可宣布的任何类型,定义AutoCAD的命令处理。如果应用程序使用CommandClass属性,它必须宣布一个实例此属性为每一类包含的AutoCAD命令处理方法。

C#:

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using System;

[assembly:

  ExtensionApplication(

    typeof(ManagedApplication.Initialization)

  )

]

[assembly:

  CommandClass(

    typeof(ManagedApplication.Commands)

  )

]

namespace ManagedApplication

{

  public class Initialization

    : Autodesk.AutoCAD.Runtime.IExtensionApplication

  {

    public void Initialize()

    {

      Editor ed =

        Application.DocumentManager.MdiActiveDocument.Editor;

      ed.WriteMessage("初始化.");

    }

    public void Terminate()

    {

      Console.WriteLine("清理");

    }

  }

  public class Commands

  {

    [CommandMethod("TST")]

    public void Test()

    {

      Editor ed =

        Application.DocumentManager.MdiActiveDocument.Editor;

      ed.WriteMessage("这是一个 TST 命令.");

    }

  }

}

 

 
posted @ 2009-03-25 16:07  野狼的天空  阅读(856)  评论(0编辑  收藏  举报