Introduction
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.
Entity ent��;
Database db= Application.DocumentManager.MdiActiveDocument.Database;
DBTransMan tm=db.TransactionManager;
using(Transaction trans=tm.StartTransaction())
{
BlockTable bt=(BlockTable)tm.GetObject(db.BlockTableId,OpenMode. ForRead,false);
BlockTableRecord btr=
(BlockTableRecord)tm.GetObject(bt,
OpenMode.ForWrite,false);
btr.AppendEntity(ent);
tm.AddNewlyCreatedDBObject(ent,true);
trans.Commit();
}
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:
Entity ent��.
Tools.AddEntity(ent);
Note: To use DOTNETARX, you must add the reference to �DOTNETARX.dll�, and import the DOTNETARX
namespace in your source code:
using DOTNETARX;
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 Circle
and Line
.
By the latest edition of DOTNETARX, I have derived from the following classes:
Line
, Circle
, Arc
, Ellipse
, Polyline
, DBText
, MText
, Table
, 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=1;
Tools.AddEntity(circle);
circle. Radius =2;
Codes using the derived classes:
Circles circle =new Circles (center, radius);
circle. Radius =1;
Tools.AddEntity(circle);
circle. Radius =2;