Tutorials 1th Chapter Hello World: Project Creation in this chapter, we will not use the Objectarx Wizard to create a new project. 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). Select the project type in the new Project dialog box as Visual Basic Engineering, then select the Class Library template, enter "LAB1" in the Project Name box, and then select the location where the project is stored. Click the OK button to create the project. 2 in the project Class1.vb 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) using Object Browser (Visual STudio. NET "View > other Window > Object Browser" menu item) to browse the classes provided by the two managed modules that are joined. 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). &NBSP;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.vb file), import the ApplicationServices, Editorinput, and runtime namespaces. imports Autodesk.AutoCAD.ApplicationServicesImports Autodesk.AutoCAD.EditorInputImports AUTODESK.AUTOCAD.RUNTIME&NBSP;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 subroutines to the class Class1. Note the use of the continuation line character "_". public Class Class1 <commandmethod ("HelloWorld") > _ public Sub HelloWorld () end SubEnd class 6) & Nbsp; &nBsp When the "HelloWorld" command runs in AutoCAD, the HelloWorld subroutine defined above is invoked. In this subroutine, an instance of a editor class is created. The editor class has related methods to access the AutoCAD command line, and it also includes selection objects and 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. In the HelloWorld subroutine, add the following code: dim ed as Editor = Application.DocumentManager.MdiActiveDocument.Editored.WriteMessage ( "Hello World") to debug this program in AutoCAD, you can let Visual Studio.NET start an 7 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 Start an external program, click the ellipsis button, and then select the 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 the managed program you just compiled. 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 "tuneThe Try menu has several items that you can use to track the running of your program. If you have time, please visit the 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.
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.