Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the access of ObjectARX .NET wrapper class in C #

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to access ObjectARX .NET wrapper classes in C #". The explanation in this article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn how to access ObjectARX .NET wrapper classes in C#.

1) start Visual Studio.NET, and select "File > New > Project" (File > New > Project). In the New Project dialog box, select the project type as "Visual C # Project", 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's Class1.cs file, a public class "Class1" has been created automatically by the system. Next, add a command to this class. To add commands, you must use the AutoCAD .NET managed wrapper class. These managed wrapper classes are contained in two managed modules. To add a reference to these two managed modules, right-click reference and select add reference. Select Browse in the add reference dialog box that pops up. In the Select components dialog box, select the installation directory of AutoCAD 2006 (assumed here as C:\ Program Files\ AutoCAD 2006\), find "acdbmgd.dll" in this directory, and select and open it. Select "Browse" again, locate "acmgd.dll" in the installation directory of AutoCAD 2006 and open it. When these two components are added, click OK in the add reference dialog box. As their name suggests, acdbmgd.dll contains ObjectDBX managed classes, while acmgd.dll contains AutoCAD managed classes.

3) use the object browser (Visual Studio.NET 's View > other Windows > object browser menu item) to browse the classes provided by the two added managed modules. Expand the "AutoCAD .NET Managed Wrapper" object (shown as acmgd in the object browser), and we will 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 text on the AutoCAD command line. Expand the "ObjectDBX .NET Managed Wrapper" object (shown as acdbmgd in the object browser) again, and the classes in this object will be used to access and edit entities in the AutoCAD drawing (this section will be covered in later chapters).

4) after referencing the ObjectARX .NET wrapper classes, we can import them. Import the ApplicationServices, EditorInput, and Runtime namespaces before the declaration statement of the Class1 class (at the top of the Class1.cs file).

Using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime

5) next, add the command to the class Class1. To add commands that can be called in AutoCAD, you must use the "CommandMethod" attribute. This attribute 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 is called. In this function, an instance of the Editor class will be created. The Editor class has methods to access the AutoCAD command line, as well as selecting objects and other important functions. The Editor object of the AutoCAD currently active document can be accessed using the Application class. After the Editor object is created, you can use its WriteMessage method to display the "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 have Visual Studio.NET start an AutoCAD process. Right-click Lab1 in the solution Manager and select Properties. In the property page dialog box of Lab1, select configure Properties > Debug. In the Startup item, select Debug Mode to Program, click the ellipsis button to the right of Startup Program, and then select acad.exe under the AutoCAD 2006 installation directory. Once set up, press F5 to start an AutoCAD process. This will compile your program and start AutoCAD automatically, and will stop when there is an error after compilation. Please correct any mistakes you may encounter.

8) the "NETLOAD" command is used to load managed programs. Enter NETLOAD on the AutoCAD command line and the Select .NET component dialog box appears. Select the "lab1.dll" generated above and open it.

9) enter "HellowWorld" on the command line. If all goes well, the text "Hello World" appears on the command line. Switch to Visual Studio.NET and add a breakpoint at the ed.WriteMessage ("Hello World"); statement. Run the HelloWorld command again in AutoCAD and you will notice that you can track the running of the code. There are several items in Visul Studio.NET 's Debug menu that can be used to track the running of a program.

If you have time, please browse the CommandMethod property. You will find it in seven different forms. In the above example, we used the simplest form, which has only one input parameter (the name of the command). You can use other forms to control how commands work, such as determining the name of the command group, global and local names, command identification (how the command runs), and so on.

Thank you for your reading. the above is the content of "how to access the ObjectARX .NET wrapper class in C#". After the study of this article, I believe you have a deeper understanding of how to access the ObjectARX .NET wrapper class in C#, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report