Click here to Skip to main content
15,880,725 members
Articles / Desktop Programming / MFC
Article

Writing AutoCad DXF files

Rate me:
Please Sign up or sign in to vote.
2.50/5 (18 votes)
24 Jan 2000 200.9K   3.9K   43   24
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


    Written By
    Canada Canada
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    Questionwhat the f*** code is it???????? Pin
    Member 1259953022-Jun-16 21:12
    Member 1259953022-Jun-16 21:12 
    GeneralMy vote of 5 Pin
    Manoj Kumar Choubey18-Feb-12 0:00
    professionalManoj Kumar Choubey18-Feb-12 0:00 
    GeneralMy vote of 2 Pin
    Fortranist20-Oct-09 22:14
    Fortranist20-Oct-09 22:14 
    GeneralMy vote of 1 Pin
    Alexandre GRANVAUD18-Mar-09 21:51
    Alexandre GRANVAUD18-Mar-09 21:51 
    QuestionHow to write an ellipse? Pin
    mudong30-Jul-06 16:45
    mudong30-Jul-06 16:45 
    GeneralDXF to C++ Pin
    Member 135964354-Feb-05 3:29
    Member 135964354-Feb-05 3:29 
    GeneralRe: DXF to C++ Pin
    Fransiscusherry8-Feb-05 0:40
    Fransiscusherry8-Feb-05 0:40 
    QuestionHow to manipulate AutoCAD files Pin
    Gasanov Tagir6-Jul-04 21:39
    Gasanov Tagir6-Jul-04 21:39 
    GeneralGreat Introduction Pin
    Tobias Wenig3-Mar-04 4:25
    Tobias Wenig3-Mar-04 4:25 
    GeneralRe: Great Introduction Pin
    Gagnon Claude3-Mar-04 15:43
    Gagnon Claude3-Mar-04 15:43 
    GeneralCan you help me with better DXF file format understanding Pin
    ValeryK11-Mar-04 2:17
    ValeryK11-Mar-04 2:17 
    GeneralRe: Can you help me with better DXF file format understanding Pin
    Tobias Wenig11-Mar-04 2:27
    Tobias Wenig11-Mar-04 2:27 
    GeneralRe: Can you help me with better DXF file format understanding Pin
    Gagnon Claude11-Mar-04 15:57
    Gagnon Claude11-Mar-04 15:57 
    General[Message Deleted] Pin
    Chuzhakin1-Nov-05 0:59
    Chuzhakin1-Nov-05 0:59 
    General[Message Deleted] Pin
    Chuzhakin1-Nov-05 0:59
    Chuzhakin1-Nov-05 0:59 
    GeneralRe: Can you help me with better DXF file format understanding Pin
    Member 1062317727-Feb-14 3:24
    Member 1062317727-Feb-14 3:24 
    I have the same problem any help please?
    GeneralCan't open in CorelDraw Pin
    Manikandan24-Dec-01 17:58
    Manikandan24-Dec-01 17:58 
    GeneralI need more about DXF Pin
    gazman3-Jul-01 20:10
    gazman3-Jul-01 20:10 
    GeneralRe: I need more about DXF Pin
    3-Jul-01 20:39
    suss3-Jul-01 20:39 
    GeneralRe: I need more about DXF Pin
    Johannes Schulte Südhoff3-Jul-01 20:58
    Johannes Schulte Südhoff3-Jul-01 20:58 
    QuestionDo you have also LightWave and DirectX? Pin
    Lev8-Feb-00 0:08
    Lev8-Feb-00 0:08 
    AnswerRe: Do you have also LightWave and DirectX? Pin
    Claude Gagnon11-Feb-00 10:40
    Claude Gagnon11-Feb-00 10:40 
    QuestionWhere is source code ? Pin
    Zuccaro Gianfranco25-Jan-00 21:11
    sussZuccaro Gianfranco25-Jan-00 21:11 
    AnswerRe: Where is source code ? Pin
    Chris Maunder26-Jan-00 10:28
    cofounderChris Maunder26-Jan-00 10:28 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.