With the newest AutoCAD 2006, the .NET programmers can use the ObjectARX Managed Wrapper Classes to develop their AutoCAD programs. But there are many inconveniences and bugs in the wrapper classes. For example, you cannot do conditional filtering, and many global functions in C++ is not provided in the wrapper class. To solve the problems, I have developed a tool “DOTNETARX” to help the .NET programmers to write the ObjectARX programs more easily.
First, let’s look at the traditional ObjectARX programs written in C#. The following example adds an entity to the AutoCAD.
Database db= Application.DocumentManager.MdiActiveDocument.Database;
BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode. ForRead,false);
Oh, I have to write so many codes only to add an entity!! Even more, when I want change the property (such as color) of the entity after it is added into the AutoCAD, I must use the same codes to open the entity (using the transaction) and then change its property. Can it be done more easily? The answer is DOTNETARX. With this tool, you can write the above codes like this:
Note: To use DOTNETARX, you must add the reference to “DOTNETARX.dll”, and import the
DOTNETARX namespace in your source code:
Now, you only need two lines of codes to finish the same thing! Can’t believe it? It’s true, your work will become simple with DOTNETARX.
DOTNETARX is a .NET assembly with many useful classes. Let’s see the main classes in DOTNETARX.
The most important class in DOTNETARX is
Tools. The members of this class are static. It has the following members:
The other classes in DOTNETARX are derived from the AutoCAD entity classes such as
By the latest edition of DOTNETARX, I have derived from the following classes:
Hatch and the
Dimensions. The names of the new classes are their ancestors’ name and with appended an ‘s’. For example,
Lines is the derived class of
Line. The first purpose of the derived classes is to create entities more easily. For example, you can only use center, radius and vector to create a circle with the original constructor of the
Circle class. But with the help of DOTNETARX, you can use three or two points to create a circle. The following example explains how to create a circle through three points:
Circles circle=new Circles(pt1,pt2,pt3);
For detailed explanation, you can refer to the help document in the accessory.
The second purpose of the derived classes is to access the entity which is added into the database. We take two examples to explain this. First is not using the derived classes:
Circle circle=new Circle (center,normal,radius);
circle. Radius =2;
Codes using the derived classes:
Circles circle =new Circles (center, radius); circle. Radius =1;
Tools.AddEntity(circle);circle. Radius =2;