Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Writing AutoCad DXF files

0.00/5 (No votes)
24 Jan 2000 1  
A simple class for writing AutoCad DXF files
  • Download source files - 16 Kb
  • Sample Image - DxfFiles.jpg

    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.

    License

    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