[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libredwg] LibreDwg: basic code sample

From: Anton.Keim
Subject: [libredwg] LibreDwg: basic code sample
Date: Thu, 21 Jan 2021 22:14:25 +0100

Dear Mr.Urban


I have been using dxflib for many years to enable an application that I have developed to export DXF files that contain mostly simple objects,  like lines and arcs.

I have just learned about LibreCad and would like to use that to export in DWG-format.

My problem is however that I cannot find a LibreDwg sample file that creates a new empty DWG object, adds some layers/lines/arcs in that dwg and then save it as a file.

I would greatly appreciate if you could provide me with a basic code sample.


Best regards


Anton Keim



I have started with a very simple sample with the following code. It creates a DWG file, but I can not open it in a CAD application. I get an error message that the file is corrupt, needs recovery. Any suggestions?


#include "dwg.h"

#include "dwg_api.h"



/* GLOBAL VARIABLES                                                        */


Dwg_Data *Dwg;

Dwg_Object_BLOCK_HEADER hdr;





int plot_DWG()


  dwg_point_3d pnt1, pnt2;


  memset(&hdr, 0, sizeof(Dwg_Object_BLOCK_HEADER));


  Dwg = dwg_add_Document(R_2000, 0, 0);


  dwg_add_LAYER(Dwg, "0");


  pnt1 = { 0., 0., 0. };

  pnt2 = { 1000., 1000., 0. };


  dwg_add_LINE(&hdr, &pnt1, &pnt2);


  dwg_write_file("D:\\Develop\\MVC\\Applications\\GUI\\RideSim\\MyfirstTest.dwg", Dwg);


  return OK;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]