Autodesk Official latest. NET tutorial (i) (C # Edition)

Source: Internet
Author: User
Tags command line join reference wrapper visual studio
Tutorials   1th Chapter          Hello World: Accessing the ObjectARX. NET Encapsulation Class    & nbsp;   in this chapter, we will use visual Studio. NET to create a new class library project. With this project, you can create a .net  DLL file that can be loaded by AutoCAD. This DLL file will add a new command named "HelloWorld" to AutoCAD. When the user runs this command, the "Hello World" text is displayed on the AutoCAD command line.  1)          Start Visual Studio.NET, select "File > New > Project" (File> new> Project). In the New Project dialog box, select the project type is Visual C # project, then select the Class Library template, enter "LAB1" in the Project Name box, and select the location where the project is stored. Click the OK button to create the project. 2          in the project Class1.cs file, a public class "Class1" has been automatically created by the system. Next, add the command to this class. To join the command, you must use AutoCAD. NET managed Encapsulation class. These managed encapsulation classes are contained in two managed modules. To add a reference to these two managed modules, right-click References and choose Add Reference. In the Add Reference dialog box that pops up, select Browse. In the Select Component dialog box, select the installation directory for AutoCAD 2006 (which is assumed to be C:\Program Files\autocad 2006\), locate "Acdbmgd.dll" in this directory, and then select and open it. Once again select "Browse" to locate "Acmgd.dll" under the installation directory of AutoCAD 2006 and open it. When these two components are joined, click the OK button in the Add Reference dialog box. As their names indicate, Acdbmgd.dll contains objectdbx managed classes, while Acmgd.dll contains AutoCAD managed classes. 3)        &NBsp Use the Object Browser (Visual Studio.NET view > Other Window > Object Browser menu items) to browse the classes that are provided by the two managed modules that you join. Expand the AutoCAD. NET Managed Wrapper object (displayed as ACMGD in the Object Browser), and we'll use the classes in this object throughout the tutorial. In this chapter, we will use an instance of the "Autodesk.AutoCAD.EditorInput.Editor" class to display the text in the AutoCAD command line. Expand the objectdbx. NET Managed Wrapper object (shown in the Object Browser as ACDBMGD), and the classes in this object will be used to access and edit the entities in the AutoCAD graphic (this section will be covered in a later section). 4)          after referencing the Objectarx. NET encapsulation classes, we can import them. Before the declaration statement of the Class1 class (at the top of the Class1.cs file), import the ApplicationServices, Editorinput, and runtime namespaces.  using autodesk.autocad.applicationservices;using autodesk.autocad.editorinput;using AUTODESK.AUTOCAD.RUNTIME; 5)          next joins the command in class Class1. To add commands that can be invoked in AutoCAD, you must use the "Commandmethod" attribute. This property is provided by the runtime namespace. Add the following properties and functions to the class Class1.  [commandmethod ("HelloWorld")]     public void HelloWorld () { } 6)           when the "HelloWorld" command runs in AutoCAD, the HelloWorld function defined above will be invoked. In this function, an instance of a editor class is created. Editor class has access to Autocad command line, which also includes selecting objects and some other important features. AutoCAD the Editor object for the currently active document can be accessed using the application class. When the editor object is created, you can use its Writemessage method to display "Hello World" text on the command line. Add the following code to the HelloWorld function:  editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Ed. Writemessage ("Hello World")           7 to debug this program in AutoCAD, you can let visual Studio.NET starts an AutoCAD process. Right-click Lab1 in Solution Manager and choose Properties. In the Lab1 Property Page dialog box, select Configure Properties > Debug. In the startup item, select Debug Mode as program, click the ellipsis button to the right of the startup program, and then select Acad.exe under the AutoCAD 2006 installation directory. When set, press F5 to start an AutoCAD process. This will compile your program and automatically start AutoCAD, and it will stop when there are errors after compiling. Please fix any errors you may encounter. 8)          "netload" command is used to load a managed program. When you enter netload in the AutoCAD command line, the selection appears. NET Components dialog box. Select the "Lab1.dll" generated above and open it. 9          Enter "Hellowworld" on the command line. If all goes well, the "Hello World" text will be displayed on the command line. Switch to Visual Studio.NET and add a breakpoint at Ed.writemessage ("Hello World") at the statement. To run the HelloWorld command again in AutoCAD, you will notice that you can track the operation of the code. Visul Studio.NET's Debug menu has several items that you can use to track the running of your program.        If you have time, please visitThe Commandmethod property. You will find that it has seven different forms. In the example above, we use the simplest form, which has only one input parameter (the name of the command). You can use other forms to control how commands work, for example, you can determine the name of the command group, the global and local names, the command ID (how commands are run), and so on.

Related Article

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.