1. Products
  2.   CAD
  3.   C++
  4.   LibreDWG

LibreDWG

 
 

Open Source C Library for AutoCAD DWG Files

Generate, Edit, Manipulate & Convert AutoCAD DWG Models via Open Source C++ API.

LibreDWG is a very useful free C library for working with AutoCAD DWG drawings. DWG is a very common and widely used file format developed by AutoDesk in the 1970s for the emerging CAD applications. Although DWG is a proprietary file format but is still commonly specified as the default file format by the contractors. The library is very easy to handle and aims to create an API that helps software developers to create applications for handling DWG files.

The library is very has included several important features for handling AutoCAD DWG files, such as accessing and reading DWG drawings, creating new DWG files from the scratch, converting new DWG files to other file formats, converters from and to DXF and JSON, converting DWG to SVG and Postscript, dwggrep to search for text, dwglayer to print the list of layers and many more.

The library allows software developers to Disable or enables DWG writing support. By default, it is not enabled and when enabled, it activates the writing support for the DWG format. Rewriting most DWGs to the r2000 format usually works fine. There are various file formats supported by DWG reader such as JSON, DXF, DXFB, GeoJSON, YAML, XML/OGR, GPX, SVG, and PS.

Previous Next

Getting Started with LibreDWG

You need to install basic development tools (a C99 compiler like gcc/clang, make, autoconf, automake and libtool). The create clone of the library using the following command.

Clone Library using the Following Command

 git clone git://git.sv.gnu.org/libredwg.git

Now change dir to libredwg folder created by git ( cd libredwg ) and issue following commands in terminal

Change dir to libredwg folder

$ sh autogen.sh 
$ ./configure --enable-trace # (this will enable debugging messages) 
$ make 
$ sudo make install 
$ make check

Create AutoCAD DWG via C Library

The Free LibreDWG C library enables software developers to create new AutoCAD DWG Files inside their own C applications. Once the file is created you can insert various types of entities inside the DWG drawings such as tables, shape, hatch, camera, light, line, mesh, mtext, polyline 2D, polyline 3D, text, table, trace, and many more. The library also supports set alignment for entities, access, and updates the properties of the entities with ease. The DWG writer has included support for various input formats, such as DXF, DXFB, and JSON.

Read AutoCAD DWG via C Library

The open source LibreDWG library has included complete support for programmatically accessing and reading AutoCAD DWG Files inside .NET applications with just a couple of lines of C code. The DWG reader supports various output formats, such as JSON, DXF, DXFB, GeoJSON. Later also YAML, XML/OGR, GPX, SVG, and PS file formats.

How to Read AutoCAD DWG via C Library?

 int error;
Dwg_Data dwg;
error = dwg_read_file(filename, &dwg);
if (!error)
{
    model_xmin = dwg_model_x_min(&dwg);
    model_ymin = dwg_model_y_min(&dwg);
    double dx = (dwg_model_x_max(&dwg) - dwg_model_x_min(&dwg));
    double dy = (dwg_model_y_max(&dwg) - dwg_model_y_min(&dwg));
    double scale_x = dx / (dwg_page_x_max(&dwg) - dwg_page_x_min(&dwg));
    double scale_y = dy / (dwg_page_y_max(&dwg) - dwg_page_y_min(&dwg));
    //...
}
dwg_free(&dwg);

Convert DWG File to SVG via C Library

SVG is a W3C standard for 2d vector graphics and is very popular. The open source LibreDWG library enables software developers to convert AutoCAD DWG drawing to SVG file formats using C commands. To convert SVG (Scalable Vector Graphics) file you need to open a DWG file and output an SVG file. Please remember that the library will handle the 2D data and will handle the 3d content from DWG since SVG only supports 2-dimensional images.