How does AutoCAD develop plug-ins through C#?

0 Preface

  AutoCAD is a computer-aided design software widely used in engineering design and construction industry. By using C# language for plug-in development, the functions of AutoCAD can be expanded to meet customized requirements. The plug-in can realize automatic drawing, data processing, batch operation and other functions to improve work efficiency and accuracy. In this article, the AutoCAD plug-in development using C# language is summarized and recorded.

1. Development tool preparation

  (1) Install Visual Studio
  Search for the "Visual Studio2022" installation package in Baidu and other browsers, and then install it.

  (2) Install AutoCAD2022
  Search "AutoCAD2022" installation package in Baidu and other browsers, and then install it.

2. VS (C#) to create plug-ins

  (1) New project
  insert image description here

  (2) Reference the link library of AutoCAD2022
  insert image description here

"acmgd.dll" "accoremgd.dll" "AcCui.dll" "acdbmgd.dll"

  (3) Set up the link library
  insert image description here

  (4) Add a namespace
  insert image description here

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;  
using Autodesk.AutoCAD.EditorInput;  
using Autodesk.AutoCAD.Runtime;  
using Autodesk.AutoCAD.Colors;

  (5) Set the external startup program
  insert image description here

  (6) Write plug-in functions
  insert image description here

[CommandMethod("TestDemo")] //指令名称
public void TestDemo()  
{
    
      
    // 声明命令行对象  
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;  
    // 向命令行输出一段文字  
    ed.WriteMessage("hello, AutoCAD!");  
}

3. Using plugins

  insert image description here

Reference materials:
[1] CREECLEEXIN. CAD programming for engineers (C# secondary development of CAD) series ; 2021-05-08 [accessed 2023-07-15].
[2] Linxson. 【C#】AutoCAD secondary development Notes ; 2022-06-13 [accessed 2023-07-15].
[3] 494. C# CAD secondary development preliminary (HelloWorld) ; 2020-09-28 [accessed 2023-07-15].
[4] bullzerone . The first example of CAD secondary development (C#) ; 2017-06-26 [accessed 2023-07-15].
[5] Ningqiang walnut cake. CAD secondary development-C# project creation ; 2019-10-11 [ accessed 2023-07-15].
[6] Where are you going, Peter. C# Cad Secondary Development Beginner Series Tutorials (1) Development Environment Construction ; 2022-10-01 [accessed 2023-07-15].
[7] Faint Xingchen. C# Actual CAD secondary development 001: CAD and C# environment configuration ; 2019-06-24 [accessed 2023-07-15].
[8] Nemo_XP. Using C# for secondary development of AutoCAD (transfer); 2018-04-14 [accessed 2023-07-15].
[9] DK Industry. c# cad secondary development ribbon interface to add a menu bar to CAD ; 2023-05-24 [accessed 2023-07-15].
[ 10] Western Regions_Snow Wolf. C# Secondary Development AutoCAD Dynamically Loads Custom Menus and Commands.pdf ; 2019-09-04 [accessed 2023-07-15].

Guess you like

Origin blog.csdn.net/qq_40640910/article/details/131739943