TheSwamp
Code Red => .NET => Topic started by: Kerry on December 02, 2005, 06:47:49 PM
-
Decided to rework the AutoCAD C# Labs < Thanks David :-) >
visit www.autodesk.com/developautocad and download the .NET training labs posted there.
I'm trying to establish a format that is in some regard tiered and scalable.
.. the classes in this particular module would be seperated into their own files within the project or solution as the code grows.
any comments ?
#region System using declarations
using System;
#endregion
#region AutoCAD Managed Wrappers using declarations
//// Assembly acdbmgd .. ObjectDBX.NET Managed Wrapper
//// Assembly acmgd .. Autocad.NET Managed Wrapper
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
#endregion
#region Alias using declarations
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
#endregion
[assembly: ExtensionApplication(typeof(ClassLibraryLab01.kwbLab01StartApp))]
[assembly: CommandClass(typeof(ClassLibraryLab01.Commands))]
namespace ClassLibraryLab01
{
#region CommandClass
//-------------------------------------------------------------------------------
public class
Commands
{
[CommandMethod("HelloWorld", CommandFlags.Modal)]
public static void Command_Hello()
{
Class1 tester = new Class1();
//call a function of the object.
tester.HelloWorld();
}
//----------------------------
[CommandMethod("ByeWorld", CommandFlags.Modal)]
public static void Command_Bye()
{
Class1 tester = new Class1();
//call a function of the object.
tester.ByeWorld();
}
//----------------------------
}
#endregion
#region Class1
//-------------------------------------------------------------------------------
public class
Class1
{
public void
HelloWorld()
{
Editor
ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("Hello World");
}
//----------------------------
public void
ByeWorld()
{
Editor
ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("Goodbye World, I'm off to join the circus");
}
}
#endregion
#region Public class kwbLab01StartApp
//-------------------------------------------------------------------------------
/// <summary>
/// The entry point for AutoCAD.
/// </summary>
public class
kwbLab01StartApp : IExtensionApplication
{
public void
Initialize()
{
Editor
ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("\n Testing Assembly kwbLab01 [kwb v:20051203]");
ed.WriteMessage("\n Type HelloWorld at the Command Line to Start ...");
ed.WriteMessage("\n Type ByeWorld at the Command Line to Finish ...");
}
public void
Terminate()
{
// Does Nothing ... can't unload NET assembly ...
}
}
#endregion
}
-
oh, and in case anyone was wondering, this is the actual first Lab solution as published :-
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
public class Class1
{
[CommandMethod("HelloWorld")]
public void HelloWorld()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("Hello World");
}
}