The Code Project View our sponsorsClick here for the free Dundas Upload controlAdvertise on the CodeProject
Home >> Files & Folders >> File Formats

Writing AutoCad DXF files
By Claude Gagnon

A simple class for writing AutoCad DXF files 
 VC5 SP2, Win9x, NT4
 Posted 25 Jan 2000
Articles by this author
Send to a friend
Printer friendly version
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
14 users have rated this article. result:
3.07 out of 5.

  • 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.

    [Top] Sign in to vote for this article:     PoorExcellent  
    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 4 of 4 (Total: 4)First Prev Next Last
    Subject 
    Author 
    Date 
      Do you have also LightWave and DirectX?
    Lev 6:08 8 Feb 00 
      Re: Do you have also LightWave and DirectX?
    Claude Gagnon 16:40 11 Feb 00 
      Where is source code ?
    Zuccaro Gianfranco 3:11 26 Jan 00 
      Re: Where is source code ?
    Chris Maunder 16:28 26 Jan 00 
    Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

    Home >> Files & Folders >> File Formats
    last updated 25 Jan 2000
    Article content copyright Claude Gagnon, 2000
    everything else © CodeProject, 1999-2001.
    The Code Project View our sponsorsClick here for Dundas Software's TCP/IP Development KitAdvertise on the CodeProject