Recently the company has been assigned to do CAD two times development. is also the first contact with this aspect of things, in fact, some do not know how to feel. Because no one on this side of the company has time to take me, can only be their own reading, and then write some demo, and then the actual application to a little learning. Needless to say, recommend a book I get started, that is, Mr. Li Guanxi's "deep habitat shallow out of AutoCAD two development", write very good, the book of the demo himself will probably know the CAD two development in the end what is a thing.
Development Environment Configuration development environment
- WIN10 x64
- CAD 2010
- Visual Studio 2012
Environment configuration
- First to install CAD software
- Create a new Class library project with Visual Studio.
- You need to add a common reference, in the CAD directory, the following three main DLL files are described below
- AcDbMgd.dll is referenced when storing an object in a graphics file.
- AcMgd.dll is referenced when working with AutoCAD applications and user interfaces.
- AcGui.dll is referenced when processing a custom file.
Program and debug write the first program
Add a class to the class library that you just created
public class FisrtCADTest{[CommandMethod("Hello")]public void Hello{ Document acDoc = Application.DocumentManager.MdiActiveDocument; Editor ed = acDoc.Editor; ed.WriteMessage("Hello World!");}}
- Compile this program
Start CAD Enter netload on the command line and find the DLL for the program you just compiled in the open window, and after loading, enter hello at the command line and guess what will happen? Yes, your first CAD two-time development program has been running flawlessly.
How to debug a program
The book describes a method, no longer repeat, the following is the way I used to
In Solution Explorer, right-click the solution and choose Add-Existing Project
In the dialog box that opens, locate the Acad.exe under the CAD installation path and select Open
Set the project you just added as the startup Project
Set project Properties
Modify the debugger type as shown in
Set breakpoints where needed, start the project, you will find the CAD program will be opened, netload loading the assembly, you can debug
C # for CAD two development environment configuration