Http://www.cnblogs.com/houlinbo/p/3325898.html
1. Development of basic information preparation
With Vs2010 for AutoCAD 2010 development, first download the Objectarx SDK.
Http://download.autodesk.com/akdlm/esd/dlm/objectarx/ObjectARX_2010_Win_64_and_32Bit.exe
2. Use Visual Studio. NET to create a new class library project
(1) Building a class library project
Start Visual Studio.NET, select File > New > Project (file> new> project). In the New Project dialog box, select a project type of Visual C # project, then select the Windows > class Library template and click the OK button to create the project.
(2) Adding references
Add Acdbmgd.dll and Acmgd.dll to the project reference, with the default location under C:/objectarx 2010/inc-win32.
After you add the references, expand the references, click Acdbmgd and Acmgd, copy their properties to false locally, or you may get a compilation error.
AutoCAD 2010 with the. NET Framework version 3.5, Vs 2010 Create a default project with the. NET Framework 4.0 version, you must change the target framework to Net framework 3.5. Modify method: Menu item >classlibrary1 properties > Application > Frame Properties, select. Net Framework 3.5.
(3) Import namespaces.
Such as:
Using Autodesk.AutoCAD.ApplicationServices;
Using Autodesk.AutoCAD.EditorInput;
Using Autodesk.AutoCAD.Runtime;
(4) Adding a custom command
To create a new HelloWorld custom AutoCAD command, you can do this:
[C-sharp]View Plaincopy
- Using System;
- Using System.Collections.Generic;
- Using System.Linq;
- Using System.Text;
- Using Autodesk.AutoCAD.ApplicationServices;
- Using Autodesk.AutoCAD.EditorInput;
- Using Autodesk.AutoCAD.Runtime;
- Namespace ClassLibrary1
- {
- public class Class1
- {
- [Commandmethod ("HelloWorld")]
- public void HelloWorld ()
- {
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- Ed. Writemessage ("Hello World");
- }
- }
- }
This command displays Hello world on the current command line.
3. Compiling and debugging
(1) Manual loading
Click Build > Build Solution to complete the compilation.
To load the generated DLL file, you must use the Netload command. Enter netload on the AutoCAD command line and select ClassLibrary1.dll to load.
Enter the HelloWorld command at the command line to see how it performs.
Netload loaded programs can not be uninstalled, you want to debug can only exit AutoCAD, and then recompile, load.
(2) Automatic loading
menu item >classlibrary1 properties > Debug > Start Action, select Start external Program, program named AutoCAD.exe, default installation location in C:/Program FILES/AUTOCAD 2010/ Acad.exe; command line parameter set/nologo/b "D:/CLASSLIBRARY1/CLASSLIBRARY1/BIN/DEBUG/START.SCR".
The Start.scr file is the AutoCAD run script file that you wrote, which is a text file that adds a line of text: Netload "d:/classlibrary1/classlibrary1/bin/debug/ ClassLibrary1.dll "
So we can run the debug directly.
(3) Commissioning
After running with the above steps, breakpoint debugging is not supported, and we should also modify the Acad.exe.config.xml file, which adds a line <supportedruntime c:/program FILES/AUTOCAD 2010/ version= "v2.0.50727"/> content. The contents of the modified Acad.exe.config.xml are as follows:
<configuration>
<startup>
<supportedruntime version= "v2.0.50727"/>
</startup>
<!--all assemblies in AutoCAD is fully trusted so there's no point generating publisher evidence-->
<runtime>
<generatepublisherevidence enabled= "false"/>
</runtime>
</configuration>
C # Objectarx AutoCAD two-time development (reprint)