Adding your own C# commands to AutoCAD

Top  Previous  Next

You will load the command using NETLOAD then the path to the DLL.

 

Inside the program you'll have somewhere this sort of thing:

 

namespace AU.MySoftware

{

  public class Initialization : IExtensionApplication

   {

      #region Commands

 

       // In this example RunSub is what you type at the AutoCAD text command prompt

       [CommandMethod("RunSub", CommandFlags.Session)]

      public static void RunSub()

       {

          Document doc = Application.DocumentManager.MdiActiveDocument;

          var db = doc.Database;

          Editor ed = doc.Editor;

 

          bool bTextInterface = false;

          if (bTextInterface)

           {

              string sOldText;

              PromptResult pr = ed.GetString("\nEnter old test: ");

              if (pr.Status != PromptStatus.OK)

               {

                  return;

               }

               sOldText = pr.StringResult;

 

              string sNewText;

               pr = ed.GetString("\nEnter new text: ");

              if (pr.Status != PromptStatus.OK)

               {

                  return;

               }

               sNewText = pr.StringResult;

 

 

              //string sSourceDir = @"C:\Users\Owen\Documents\LuVe\SUBRUN_TESTS_IN";

              //string sDestDir = @"C:\Users\Owen\Documents\LuVe\SUBRUN_TESTS_OUT";

              //string[] DwgList = Directory.GetFiles(sSourceDir, "*.dwg");

 

              // Copy picture files.

              //foreach (string sDwgFile in DwgList)

               {

                  // Substituter Subber = new Substituter(sOldText, sNewText, sDwgFile, sDestDir);

               }

           }

          else

           {

              MainDialog MainDlg = new MainDialog();

               Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(MainDlg);

           }

       }

 

As far as I can tell #region Commands and [CommandMethod("RunSub", CommandFlags.Session)] is the thing that marks the function as a command.