Click here to Skip to main content
13,662,574 members
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 7 Jun 2005

Using DOTNETARX To Develop Your .NET ObjectARX Applications

, 7 Jun 2005
Rate this:
Please Sign up or sign in to vote.
With the help of DOTNETARX, .NET programmers can write their ObjectARX programs more easily.


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=

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……. 


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:

  • Properties:
    • Database: gets the current AutoCAD database.
    • Editor: gets the editor associated with the current document.
    • TransactionManager: gets transaction manager of the current database.
  • Functions:

    With the three properties, you can replace the long codes such as Application.DocumentManager.MdiActiveDocument.Database with Tools.Database.

    • public static ObjectId AddEntity(Entity ent)

      Adds an entity to the current AutoCAD drawing. The following codes add a line to the database:

      Line line;
    • public static ObjectId AddSymbolTableRecord(SymbolTableRecord str,ObjectId symbolTableId)

      Adds symbol table records to the current database. The following codes add a new layer to the database:

      LayerTableRecord ltr;
    • public static ObjectId AddDictionaryObject(string searchKey)

      Adds the dictionary object to the current database.

    • public static ObjectId AddDictionaryObject(string searchKey,DBObject newValue,ObjectId ownerId)

      Adds dictionary objects such as XRecords and groups.

    • Functions used to set or get the general properties of an entity:

      The properties are: Color, ColorIndex, Layer, Linetype, LinetypeScale, LineWeight, PlotStyleName and Visible. The name of the function which sets the general properties of an entity starts with Put, and then followed by the property’s name. For example, PutColor is used to set the color of an entity. There are two forms of this kind of function.

      1. The first one is PutColor(Entity ent,Color color), the ent parameter is for the entity, and color is for the color value.
      2. The second one is PutColor(ObjectId id,Color color), the id parameter is for the object Id of the entity, and color is for the color value.

      The name of the function which gets the general properties of an entity starts with Get, and then followed by the property’s name. For example, GetColor is used to get the color of an entity. There are two forms of this kind of function.

      1. The first one is GetColor(Entity ent), the ent parameter is for the entity.
      2. The second one is GetColor(ObjectId id), the id parameter is for the object Id of the entity.
    • public static void Move(Entity ent,Point3d fromPoint,Point3d toPoint)

      Moves an entity object along a vector.

    • public static void Rotate(Entity ent,Point3d basePoint,double rotationAngle)

      Rotates an entity object around a base point.

    • public static void Scale(Entity ent,Point3d basePoint,double scaleFactor)

      Scales an entity object equally in the X, Y, and Z directions.

    • public static ObjectId Mirror(Entity ent,Point3d mirrorPoint1,Point3d mirrorPoint2,bool eraseSourceObject)

      Creates a mirror-image copy of a planar entity object around an axis.

    • public static ObjectId Copy(Entity ent)

      Duplicates the given entity object to the same location.

    • public static void Erase(Entity ent)

      Erases the given entity object.

    • public static Entity GetEntity(ObjectId id)

      Gets AutoCAD entity object by its object ID.

    • public static DBObject GetDBObject(ObjectId id)

      Gets AutoCAD DBObject by its object ID.

    • public static DBObjectCollection GetIteratorForSymbolTable(ObjectId id)

      Gets an iterator. It is used to iterate through a symbol table record.

    • public static ObjectIdCollection GetIteratorForSymbolTableID(ObjectId id)

      Gets an iterator. It is used to iterate through a symbol table record.

    • public static Point3d GetMidPoint(Point3d pt1,Point3d pt2)

      Gets the midpoint of two points.

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); 
//Because the circle is not added into database, 
//changing the circle’s radius is allowed 
//Add the circle into the database 
circle. Radius =2;
//Error,because the circle is added into the database,
//you must open it first, then operate on it

Codes using the derived classes:

Circles circle =new Circles (center, radius);//even the constructor is more simple
      circle. Radius =1;// Because the circle is not added into database, 
                        // changing the circle’s radius is allowed

Tools.AddEntity(circle);// Add the circle into the database 
// Though the circle is added into the database, you can edit its property
circle. Radius =2;


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

China China
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
ray889912-Sep-10 5:27
memberray889912-Sep-10 5:27 
QuestionOpen and send command to Acad Pin
Habeeb.net21-Jul-08 5:05
memberHabeeb.net21-Jul-08 5:05 
GeneralDotNetARX 5.0 supports for Linq and .NET3.5 features such as extension method Pin
csharpbird7824-Nov-07 20:12
membercsharpbird7824-Nov-07 20:12 
GeneralUCS Pin
shers11-Nov-07 19:21
membershers11-Nov-07 19:21 
QuestionHow can I write a program for AutoCad? Pin
mrv230026-Sep-07 22:44
membermrv230026-Sep-07 22:44 
GeneralNeed advise when using Autocad file Pin
sanong27-Aug-07 19:41
membersanong27-Aug-07 19:41 
GeneralPS to previous post on Acad 2007 Pin
tedcx26-Jan-07 8:58
membertedcx26-Jan-07 8:58 
GeneralAcad 2007 upgrade Pin
tedcx26-Jan-07 8:54
membertedcx26-Jan-07 8:54 
QuestionTools.AddEntity(circle) throws an exception Pin
tedcx25-Jan-07 13:36
membertedcx25-Jan-07 13:36 
QuestionUsing command line arguements Pin
davethiss1-Sep-06 6:15
memberdavethiss1-Sep-06 6:15 
QuestionAutoCAD 2006 Pin
Varun Jain Varun Jain26-Aug-06 20:04
memberVarun Jain Varun Jain26-Aug-06 20:04 
Generalinstallation of autocad 2006 Pin
Adnan Siddiqi14-Jun-05 19:19
memberAdnan Siddiqi14-Jun-05 19:19 
QuestionWhere's the CODE? Pin
Bababooey10-Jun-05 21:34
memberBababooey10-Jun-05 21:34 
GeneralDOTNETARX now can use conditional selectionset. Pin
arxbird9-Jun-05 14:57
memberarxbird9-Jun-05 14:57 
QuestionNo sources ??? Pin
Hartmut Kluge7-Jun-05 22:19
memberHartmut Kluge7-Jun-05 22:19 
AnswerRe: No sources ??? Pin
arxbird8-Jun-05 15:44
memberarxbird8-Jun-05 15:44 
GeneralRe: No sources ??? Pin
Apuhjee21-Nov-06 19:17
memberApuhjee21-Nov-06 19:17 
GeneralRe: No sources ??? Pin
djonio14-Dec-06 1:15
memberdjonio14-Dec-06 1:15 
GeneralFinally an Article in this topic!! Pin
d00_ape7-Jun-05 21:58
memberd00_ape7-Jun-05 21:58 
GeneralRe: Finally an Article in this topic!! Pin
arxbird8-Jun-05 15:40
memberarxbird8-Jun-05 15:40 
GeneralRe: Finally an Article in this topic!! Pin
d00_ape8-Jun-05 21:49
memberd00_ape8-Jun-05 21:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 7 Jun 2005
Article Copyright 2005 by arxbird
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid