欢迎加我的QQ群:193522571,一起来讨论、交流!

AutoCAD中static 和 instance class的区别

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(CommandClasses.FirstClass))]

[assembly: CommandClass(typeof(CommandClasses.SecondClass))]

namespace CommandClasses

{

  static public class FirstClass

  {

    private static int counter = 0;

    [Autodesk.AutoCAD.Runtime.CommandMethod("glob")]

    public static void global()

    {

      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

      ed.WriteMessage("\nCounter value is: " + counter++);

    }

  }

  public class SecondClass

  {

    private int counter = 0;

    [Autodesk.AutoCAD.Runtime.CommandMethod("loc")]

    public void local()

    {

      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

      ed.WriteMessage("\nCounter value is: " + counter++);

    }

  }

}

 

Here’s what happens when you execute the two commands in two separate documents:

[From first drawing...]

Command: glob

Counter value is: 0

Command: glob

Counter value is: 1

Command: glob

Counter value is: 2

Command: loc

Counter value is: 0

Command: loc

Counter value is: 1

Command: loc

Counter value is: 2

Command: new

[From second drawing...]

Command: glob

Counter value is: 3

Command: glob

Counter value is: 4

Command: glob

Counter value is: 5

Command: loc

Counter value is: 0

Command: loc

Counter value is: 1

Command: loc

Counter value is: 2

posted @ 2018-01-14 14:47  swtool  阅读(220)  评论(0编辑  收藏  举报
欢迎加我的QQ群:193522571,一起来讨论、交流!