How to import and export AutoCAD (DWG/DXF) files in your application?

How to import and export AutoCAD (DWG/DXF) files in your application?

AutoCAD is amongst the most popular CAD software and has been around for almost three decades now. DWG (.dwg – DraWinG) is AutoCAD’s native file format. It is in binary form and is proprietary. DWG typically stores the design information using geometrical elements, dimensioning information, material information and user data (or metadata). Because of the popularity of AutoCAD, it has become a de facto standard for 2D and 3D design data. AutoCAD also supports .dxf format which is a representation of .dwg, but is meant for data exchange (interoperability). The specifications of DXF files are publically available on Autodesk’s website.

According to the estimates from Autodesk, there were in excess of two billion DWG files in existence in 19981. Because of this enormous content available in DWG format, most of the engineering applications desire to support reading it. There are a few ways to support importing and exporting of DWG files in your application. At ProtoTech Solutions, we have delivered DWG import and export solutions to many clients using different approaches (see Fig.1). Here is a brief description of various approaches to solving this problem.

  1.  RealDWG© SDK:

Autodesk provides the RealDWG Software Development Kit. Using the RealDWG APIs (Application Programmers’ Interface), C++ and .NET developers can read and write DXF and DWG files in their applications. The RealDWG libraries (DLLs) are required to be redistributed along with the application.

         Pros: We have been able to produce a very high fidelity import results using RealDWG. There are a good number of sample programs provided along with the SDK. The documentation is extensive. If you are a member of ADN (Autodesk Developer Network), then you can expect a good technical support as well. Since RealDWG is an Autodesk product, it’s release follows every major AutoCAD release thereby making it easy for you to make your application compatible with the latest version of the DWG format. There is a good amount of learning curve involved with this SDK.

        Cons: DWG has a quirky database-like format which is a little difficult to understand. Iterating the tables, supporting each and every type of entity, reading geometry and attributes will require time and many lines of code. Some attributes (e.g. color of entity which can change depending upon what background the user has set in the AutoCAD window) tend to be more of behavioral sorts than just a static property and these can be quite challenging to import to mimic in the application because the context (the particular AutoCAD instance) is not available. We have also observed that the memory consumption when reading 3D solids can shoot up. Importing custom objects (using Object Enablers) requires some juggling to get working. Finally, RealDWG is supported only on Windows.

Tech Soft 3D is the worldwide exclusive reseller of RealDWG. The licensing process may involve a thorough review of your application by Autodesk to ensure there isn’t a competition and we believe this may be the biggest first step in using RealDWG to import DWG files in your application.

  1. Teigha®:

Teigha is a development platform supporting the reading and writing of DWG, DXF and DGN files.

        Pros:  It is released by Open Design Alliance (ODA) which boasts a membership of 1200 including IntelliCAD, Caddie, ZWSoft, BricSys etc.. Teigha is available for C++ and .NET developers. Visual Basic and other COM-based developers can use TeighaX ActiveX interface. Teigha interface resembles very closely with the RealDWG. Teigha does use some modern features of programming languages viz. smart pointers etc. which makes it a little easy to use. Teigha distribution has numerous samples which can come very handy.

Teigha is also well integrated with third-party components via ACIS (3D Solid Modeler), HOOPS & Redway3D (3D Graphics), FlySDK (PDF support). Teigha is supported on Windows, Macintosh OSX & iOS, UNIX/Linux, and Android.

      Cons: The support and cost will vary based on the membership levels. There is usually a time gap between the release of the latest DWG format and its full support by Teigha. This can be a critical factor for some applications. We have observed that Teigha supports many entities fully, but there are some which don’t seem to match.

Happy Importing!

Author: Rajesh Bhartiya(CEO, ProtoTech Solutions)

Rajesh is passionate about computers in engineering and has been designing software applications for over fifteen years. He has contributed significantly to the development of any 3D graphics libraries, geometry kernel, and data exchange modules. He has consulted to many big software companies on design and optimization including applications for piping design, inspection, and measurement, building information management etc.

Author: Rajesh Bhartiya
Contact us:
ProtoTech Solutions