]> Shamusworld >> Repos - architektonas/blob - dxflib/doc/manual/en/writing.xml
Fixed problem with MDI activation.
[architektonas] / dxflib / doc / manual / en / writing.xml
1 <manstyle>
2   <opt name="PageTitle" value="Writing DXF Files" />
3   <section>Writing DXF Files</section>
4   <idx>Writing,Output,DL_Codes,DXF 2000,DXF 2002,R12</idx>
5
6   <para>
7   To write a DXF file, you need to wrap the entities, layers, blocks, ..
8   you have into the wrapper classes of dxflib. Since dxflib does not
9   store any entities, you need to iterate through your entities and
10   call the write functions for each of them. Please note that you 
11   have to stick to the exact order in which you call the write
12   functions of dxflib. Otherwise your DXF file will not be standard
13   conform.
14   </para>
15
16   <subsection>Creating the Writer Object</subsection>
17
18   <para>
19   To create a DXF writer object you need to specify the file name
20   as well as the DXF version you want to produce. At the time of
21   writing only two DXF versions were supported: R12 and 
22   DXF 2000/2002. The dxflib codes for DXF version R12 is
23   DL_Codes::AC1009 and for DXF 2000/2002 DL_Codes::AC1015.
24   </para>
25
26   <para>
27   There are two APIs you will need to write a DXF file. The
28   API in DL_WriterA offers low level functions to write basic 
29   key/value tuples on which a DXF file is based. 
30   Creating a valid DXF file using only these functions would
31   be very difficult and inconvenient. Therefore, there is
32   a higher level API in the DL_Dxf class which allows you
33   to write for example a whole line without knowing the
34   key/value tuples that are needed for it.
35   </para>
36
37   <para>
38   The following code creates and opens a file for a DXF 2000/2002
39   drawing: 
40   </para>
41
42   <includecode src="code/write01.cpp" />
43
44   <!-- Header -->
45   
46   <subsection>
47   Writing the DXF Header
48   </subsection>
49   <idx>Header</idx>
50
51   <subsubsection>
52   Opening the DXF Header
53   </subsubsection>
54
55   <para>
56   The DXF header contains information about the DXF version. It has
57   to be written before anything else with 
58   </para>
59
60   <includecode src="code/write02.cpp" />
61
62   <para>
63   The following list shows how a DXF header typically looks like:
64   </para>
65
66   <includecode src="code/header.dxf" />
67   
68   <para>
69   As you can see, the writeHeader() function does not close
70   the header. This is because you might want to store a set of
71   variables into it. If you have to store variables, you have to 
72   do it now. If not, proceed with "Closing the Header".
73   </para>
74
75   <subsubsection>
76   Storing Additional Variables
77   </subsubsection>
78   <idx>Variables</idx>
79
80   <para>
81   Variables in the DXF header are used to store meta data for 
82   the drawing contained in the file. For a description of
83   all supported variables, please refer to the DXF documentation
84   <a href="appendix_bib.html#dxf">[DXF]</a>.
85   </para>
86
87   <para>
88   The following code snippet shows examples for storing variables of 
89   different types. You can store as many variables as you need but
90   you have to stick to the supported variable names and types in order
91   to create a valid DXF file.
92   </para>
93   
94   <includecode src="code/write03.cpp" />
95   
96   <subsubsection>
97   Closing the Header
98   </subsubsection>
99
100   <para>
101   Use the following code to close the DXF header (end the current section):
102   </para>
103
104   <includecode src="code/write04.cpp" />
105
106   <!-- Tables -->
107
108   <subsection>
109   Writing the Tables Section
110   </subsection>
111   <idx>Tables</idx>
112
113   <subsubsection>
114   Opening the Tables Section
115   </subsubsection>
116
117   <para>
118   The tables section of a DXF file contains some tables defining 
119   viewports, linestyles, layers, etc.
120   </para>
121
122   <para>
123   Open the tables section with the function:
124   </para>
125
126   <includecode src="code/write10.cpp" />
127
128   <subsubsection>
129   Writing the Viewports
130   </subsubsection>
131   <idx>Viewports</idx>
132
133   <para>
134   Viewports are not directly supported by dxflib. However, they 
135   still need to be there in a valid DXF file. You can write the
136   standard viewports using the function:
137   </para>
138   
139   <includecode src="code/write11.cpp" />
140   
141   <subsubsection>
142   Writing the Linetypes
143   </subsubsection>
144   <idx>Linetypes</idx>
145
146   <para>
147   Only linetypes that are actually used need to be defined in the 
148   DXF file. For simplification, you might want to store all 
149   linetypes supported by dxflib as shown below.
150   </para>
151
152   <includecode src="code/write12.cpp" />
153   
154   <subsubsection>
155   Writing the Layers
156   </subsubsection>
157   <idx>Layers</idx>
158
159   <para>
160   Layers are a substantial part of most DXF drawings. All layers
161   that are used in the drawing need to be defined in this 
162   table section. The following example code writes three layers
163   with names "0", "mainlayer" and "anotherlayer" to the DXF file.
164   Note that before writing the layers, you need to specify 
165   how many layers there are in total. Layer "0" is the default
166   layer. It cannot be omitted.
167   </para>
168
169   <includecode src="code/write13.cpp" />
170
171   <para>
172   The default line width is given in 1/100mm. The color enum
173   in namespace DL_Codes defines the most common colors.
174   </para>
175
176   <subsubsection>
177   Writing Various Other Tables
178   </subsubsection>
179
180   <para>
181   These tables are also needed. For more information, please refer
182   to the DXF documentation <a href="appendix_bib.html#dxf">[DXF]</a>.
183   </para>
184   
185   <includecode src="code/write14.cpp" />
186
187   <subsubsection>
188   Writing Dimension Styles
189   </subsubsection>
190   <idx>Dimension Styles</idx>
191
192   <para>
193   Dimension Styles define the look of dimensions.
194   </para>
195
196   <includecode src="code/write15.cpp" />
197   
198   <subsubsection>
199   Writing Block Records
200   </subsubsection>
201   <idx>Block Records</idx>
202
203   <para>
204   Block records define the names of available blocks in the DXF
205   file. The following example declares the existence of two blocks 
206   with names "myblock1" and "myblock2". Note that the first
207   call is also needed. It opens the blocks table and writes 
208   some standard blocks that might be required by the DXF 
209   version.
210   </para>
211
212   <includecode src="code/write16.cpp" />
213   
214   <subsubsection>
215   Ending the Tables Section
216   </subsubsection>
217
218   <includecode src="code/write17.cpp" />
219
220   <subsection>
221   Writing the Blocks Section
222   </subsection>
223   <idx>Blocks</idx>
224
225   <para>
226   The blocks section defines the entities of each block.
227   </para>
228
229   <includecode src="code/write20.cpp" />
230   
231   <subsection>
232   Writing the Entities Section
233   </subsection>
234   <idx>Entities</idx>
235
236   <para>
237   The entities section defines the entities of the drawing. The 
238   two entities in the following example use the attributes
239   of their layer (256 = color by layer, -1 = line width by layer, 
240   "BYLAYER" = line style by layer). 
241   </para>
242
243   <includecode src="code/write30.cpp" />
244   
245   <subsection>
246   Writing the Objects Section
247   </subsection>
248   
249   <includecode src="code/write40.cpp" />
250   
251   <subsection>
252   Ending and Closing the File
253   </subsection>
254   
255   <includecode src="code/write50.cpp" />
256
257 </manstyle>
258