01. "Hello world" message in AutoCAD editor Example


01.Start up with the Environment

  • Language: C#
  • IDE: VS2019
  • CAD: 2019

The relationship between CAD edition and product codes for installation

R19.0: 2013
R19.1: 2014
R20.0: 2015
R20.1:2016
R21.0:2017
R22.0:2018
R23.0:2019
R23.1:2020  
R24.0:2021


02. Create a new project

Build up a class file which can be loaded by AutoCAD later for use.

  1. Start Visual Studio

Create new project

  1. Create new project with .NetFramework 4.7
    Input the Project name

03. Load the files

The we load the .dll file in the AutoCAD root folder into the projects, then the code we write can use them to command AutoCAD.

Load AutoCAD assembly files

turn “copy Local” to False

The brief info the main three .dll files are listed as below.

AcDbMgd.dll. Use when working with objects in a drawing file.
AcMgd.dll. Use when working with the AutoCAD application.
AcCui.dll. Use when working with customization files.

04. Write the code

Once we load the .dll files, Visual Studio is smart enough to remind us to using the right assembly as show in the figure below.

Using the assembly

namespace _01.Environment_Build_up_Demo
{
    public class Class1
    {
        [CommandMethod("CommandDemo")]
        public void Demo1()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("Hello World");
        }

    }
}


05. Build up the code

Main Menu -> Build -> Rebuild solution
then the .dll file will be built up.
Build up the first .dll file

Several seconds later, we can see the “succeeded” information.

Succeeded in Build-up


06. Run the code in AutoCAD

The we need to start up AutoCAD, and then input netload to load the .dll we write into CAD,

Load our dll file

The we input the command into the

CommandDemo

Show up the message


07. Solution files in VS

Project and solution files have the following file extensions:

  1. VBPROJ - Microsoft Visual Basic (VB) .NET project file
  2. CSPROJ - Microsoft Visual C# project file
  3. SLN - Microsoft Visual Studio solution file```

Reference

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD .NET Developer’s Guide/index.html?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-3e30.htm,topicNumber=d0e26245


Author: Ford Yang
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Ford Yang !
  TOC