DXF文件格式读取(VC例子)
Download demo project - 167 Kb
dxf文件怎么打开
Introduction
What is DXF?
Drawing Interchange Format (DXF) files enable the interchange of drawings between AutoCAD and other programs. DXF files can be either ASCII or binary formats. Because ASCII DXF files are more common than the binary format, CadLib uses ASCII DXF format.
What is CadLib?
The CadLib is not a Computer Aided Design (CAD) program. It is a tool for creating DXF files that are used in the CAD programs. It consists of two parts. One of them is a Dynamic Link Library to create the DXF file. The other part is the programming interface. It is a class that integrates the cadio.dll functions. It can be used in Microsoft Visual C++ projects. In addition, the cadio.dll can be used in other Win32 programs.
Why use CadLib?
In some programs, it is needed to create a drawing output for use in other programs such as AutoCad. For example, in a "Building Detail Sheet Generator Program", the program needs to create a drawing output. And the most standard format for communicating drawing data is DXF.
DXF file structure
The DXF format is a tagged data representation of all the information contained in a drawing file. Tagged data means that each data element in the file is preceded by an integer number that is called a group code. A group code's value indicates what type of data element follows. This value also indicates the meaning of a data element for a given object (or record) type. Virtually all user-specified information in a drawing file can be represented in DXF format. (from AutoCad's DXF reference)
A DXF file consists of some sections. Each section has some drawing data in itself. The C
adLib uses the following sections:
1. HEADER
2. TABLES
3. BLOCKS
4. ENTITIES
The main reference for DXF file structure that is used for CadLib is the AutoCad's DXF reference. You can find more information about DXF file structure here.
Classes
The classes are interfaces between CadIO.dll and the main program. "Test" has come with CadLib to demonstrate how to generate a DXF file with CDxfFileWrite and CDrawing classes.
CDxfFileWrite class
CDxfFileWrite gathers all the commands needed to directly create a DXF file. Usage of CDxfFileWrite is as follows:
1. Create the DXF file
Collapse | Copy Code
CDxfFileWrite dxffile;
dxffile.Create( "d:\\test.dxf" );
2. Begin and end the HEADER section. It's here for compatibility with some CAD programs. Others work without having HEADER section.
Collapse | Copy Code
// Header Section ------------------------------------------
dxffile.BeginSection(SEC_HEADER);
dxffile.EndSection();
// close HEADER section ------------------------------------
3. Begin the TABLES section and put the LAYER, LTYPE, STYLE, DIMSTYLE table-types as many as you want and then close the section
Collapse | Copy Code
// Tables Section ------------------------------------------
dxffile.BeginSection(SEC_TABLES);
// LTYPE table type -------------------------
dxffile.BeginTableType(TAB_LTYPE);
DXFLTYPE ltype;
double elem[4];
// Continuous
ZeroMemory(<ype, sizeof(ltype));
ltype.Name = "Continuous";
ltype.DescriptiveText = "Solid line";
dxffile.AddLinetype(<ype);
// DASHDOT2
ZeroMemory(<ype, sizeof(ltype));
ltype.Name = "DASHDOT2";
ltype.DescriptiveText = "Dash dot (.5x) _._._._._._._._._._._._._._._.";
ltype.ElementsNumber = 4;
ltype.TotalPatternLength = 0.5;
ltype.Elements = elem;
elem[0] = 0.25;
elem[1] = -0.125;
elem[2] = 0.0;
elem[3] = -0.125;
dxffile.AddLinetype(<ype);
dxffile.EndTableType();
// close LTYPE table type -------------------
// LAYER table type -------------------------
result &= dxffile.BeginTableType(TAB_LAYER);
result &= dxffile.AddLayer("Layer1", 1, "Continuous");
result &= dxffile.AddLayer("Layer2", 2, "Continuous");
result &= dxffile.AddLayer("Layer3", 3, "Continuous");
result &= dxffile.AddLayer("Layer4", 4, "Continuous");
result &= dxffile.EndTableType();
// close LAYER table type -------------------
// STYLE table type -------------------------
dxffile.BeginTableType(TAB_STYLE);
DXFSTYLE tstyle;
ZeroMemory(&tstyle, sizeof(tstyle));
tstyle.Name = "Style1";
tstyle.PrimaryFontFilename = "TIMES.TTF";
tstyle.Height = 0.3;
tstyle.WidthFactor = 1;
dxffile.AddTextStyle(&tstyle);
dxffile.EndTableType();
// close STYLE table type -------------------
// DIMSTYLE table type ----------------------
dxffile.BeginTableType(TAB_DIMSTYLE);
DXFDIMSTYLE dimstyle;
// DIM1
ZeroMemory(&dimstyle, sizeof(dimstyle));
dimstyle.Name = "DIM1"; // DimStyle Name

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。