1. The AutoCAD. NET API consists of different DLL files that provide rich classes, structures, methods, and events for accessing graphics files or AutoCAD applications. Each DLL file defines a different namespace that uses a feature-based library organization component.
Here are the three main DLL files that you will frequently use for the AutoCAD. NET API:
AcDbMgd.dll. Use this DLL file when using objects in a graphics file.
AcMgd.dll. Use this DLL file when using AutoCAD applications.
AcCui.dll. Use this DLL file when you use a custom file.
Note: When you create a CAD project, you need to refer to the DLL above, which is generally used in the previous two. If the AutoCAD. NET API DLL is referenced, you must set the copy to local property of the reference DLL file to False. Copy to local property determines whether a copy of the referenced DLL file is created when Microsoft Visual Studio compiles the project and places it in the same directory as the project assembly file. Because the reference file is already an AutoCAD satellite file, creating a copy of the referenced file can cause unexpected results when the assembly file is loaded into AutoCAD.
2. Adding a CAD-callable command to a. NET class, you must use the Commandmethod property, which is provided by the runtime namespace. The code looks like this
1 ImportsAutodesk.AutoCAD.Runtime2 ImportsAutodesk.AutoCAD.ApplicationServices3 ImportsAutodesk.AutoCAD.DatabaseServices4 5 Public ClassMyHello6<commandmethod ("Hello") > _7 Public SubHello ()8 'Gets the editor object for the currently active document.9 DimDoc asAutodesk.AutoCAD.ApplicationServices.Document =Application.DocumentManager.MdiActiveDocumentTen DimEd asAutodesk.AutoCAD.EditorInput.Editor =Doc.editor OneEd.writemessage ("Hello") A - End Sub - End Class
3. After the CAD project generates the class library, you can enter the netload command from the AutoCAD command prompt, select the generated DLL, load the CAD project, and use the Commandmethod specified command in CAD.
4, CAD Debugging (Take CAD2010, VS2010 for example): Right-click to open the project properties--debugging--choose to start the external program \autocad2010\acad.exe
Breakpoints do not work as follows
(Workaround excerpt from: http://www.cnblogs.com/junqilian/archive/2010/04/29/1724403.html)
Breakpoints do not work because Visual Studio 2010 starts the default debugger (v4.0) when debugging, but in order for our. NET applications to run on AutoCAD Map (or Revit), we need. NET 2.0 The framework (3.5 is also running on top of CLR 2.0).
The solution has the following two scenarios:
Scenario 1
Edit the config file of the host program (Acad.exe.config, Revit.exe.config, etc.), this file is in the installation directory of AutoCAD. Add the following code in front of </configuration> (CAD2010 the line code has been commented):
<startup>
<supportedruntime version= "v2.0.50727"/>
</startup>
Scenario 2
Add the host EXE file as an existing project to your solution and set the debugger to v2.0
Right-click Solution Explorer, select Add->existing Project, browse to the startup file for AutoCAD Acad.exe
Right-click the project and set it as Startup Project set as Startup projects
Open the Project Properties dialog box property
Set Debugger Type to Managed v2.0
5. For different versions of AutoCAD, the recommended version of the. NET framework is as follows:
2007-2009, Framework 2.0
2010-2011, Framework 3.5
2012-2013, Framework 4.0
Based on. NET CAD two-time development learning Note one: Getting Started with CAD development