Writing AutoCad DXF files






2.50/5 (18 votes)
Jan 25, 2000

203222

3926
A simple class for writing AutoCad DXF files
This article demonstrate how to write an ASCII DXF files. A DXF file is a file composed of sections and associated values. They are read by AutoCad and then converted to a drawing.
I have developped a class CDxf to write a DXF file from an application. Then the user must use AutoCad to interpret the DXF file.
I have included only a small portion of what can be do with DXF files. All the details are contained in the following document from the AutoDesk web site : http://www.autodesk.com/techpubs/autocad/dxf/.
// Here is the code to write a DXF file that will draw a circle in AutoCad. // void CDxf::Circle () { // 1000 diameter circle // Creation of an output stream objet in text mode. // ios::app : append ofstream FichierDxf ("TestDxf.dxf", ios::app); // Draw the circle FichierDxf << 0 << endl; FichierDxf << "CIRCLE" << endl; FichierDxf << 8 << endl; // Group code for layer name FichierDxf << 0 << endl; // Layer number FichierDxf << 10 << endl; // Center point of circle FichierDxf << 0.0 << endl; // X in OCS coordinates FichierDxf << 20 << endl; FichierDxf << 0.0 << endl; // Y in OCS coordinates FichierDxf << 30 << endl; FichierDxf << 0.0 << endl; // Z in OCS coordinates FichierDxf << 40 << endl; // radius of circle FichierDxf << 500.0 << endl; FichierDxf.close(); }
By being able to write a DXF file, I can integrate into my applications a way to share information with AutoCad. Obviously there is a lot more that can be added to this class.