Author Topic: Lab 01 Reworked ..  (Read 4907 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Lab 01 Reworked ..
« 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 ?
Code: [Select]
#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
}


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Lab 01 Reworked ..
« Reply #1 on: December 02, 2005, 07:21:47 PM »
oh, and in case anyone was wondering, this is the actual first Lab solution as published :-

Code: [Select]
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");
}
}
« Last Edit: December 03, 2005, 07:40:34 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.