C # Objectarx AutoCAD two-time development (reprint)

Source: Internet
Author: User

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
  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Linq;
  4. Using System.Text;
  5. Using Autodesk.AutoCAD.ApplicationServices;
  6. Using Autodesk.AutoCAD.EditorInput;
  7. Using Autodesk.AutoCAD.Runtime;
  8. Namespace ClassLibrary1
  9. {
  10. public class Class1
  11. {
  12. [Commandmethod ("HelloWorld")]
  13. public void HelloWorld ()
  14. {
  15. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  16. Ed. Writemessage ("Hello World");
  17. }
  18. }
  19. }

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.