📄 dxf.htm
字号:
nates in the dxf file. you'll have to know the method by which
autocad calculates the x and y axes in order to work with these
values.
o the elevation value stored with an entity and output in dxf files
will be a sum of the z coordinate difference between the ucs xy
plane and the ecs xy plane, and the elevation value that the user
specified at the time the entity was drawn.
</pre>
<pre>arbitrary axis algorithm</pre>
<pre>the arbitrary axis algorithm is used by autocad internally to implement the
"arbitrary but consistent" generation of entity coordinate systems for all
entities except lines, points, 3d faces, and 3d polylines, which contain
points in world coordinates.</pre>
<pre>given a unit-length vector to be used as the z axis of a coordinate system,
the arbitrary axis algorithm generates a corresponding x axis for the coor-
dinate system. the y axis follows by application of the right hand rule.</pre>
<pre>the method is to examine the given z axis (also called the normal vector)
and see if it is close to the positive or negative world z axis. if it is,
cross the world y axis with the given z axis to arrive at the arbitrary x
axis. if not, cross the world z axis with the given z axis to arrive at
the arbitrary x axis. the boundary at which the decision is made was
chosen to be both inexpensive to calculate and completely portable across
machines. this is achieved by having a sort of "square" polar cap, the
bounds of which is 1/64, which is precisely specifiable in 6 decimal frac-
tion digits and in 6 binary fraction bits.</pre>
<pre>in mathematical terms, the algorithm does the following (all "vectors" are
assumed to be in 3d space, specified in the world coordinate system).</pre>
<pre> let the given normal vector be called n.
let the world y axis be called wy, which is always (0,1,0).
let the world z axis be called wz, which is always (0,0,1).</pre>
<pre> 19
autocad reference manual</pre>
<pre>we are looking for the arbitrary x and y axes to go with the normal n.
they'll be called ax and ay. n could also be called az (the arbitrary z
axis).</pre>
<pre> if (nx < 1/64) and (ny < 1/64) then
ax = wy * n (where "*" is the cross-product operator).
otherwise,
ax = wz * n.
scale ax to unit length.</pre>
<pre>the method of getting the ay vector would be:</pre>
<pre> ay = n * ax.
scale ay to unit length.
</pre>
<pre>c.1.6 writing dxf interface programs</pre>
<pre>writing a program that communicates with autocad via the dxf mechanism
often appears far more difficult than it really is. the dxf file contains
a seemingly overwhelming amount of information, and examining a dxf file
manually may lead to the conclusion that the task is hopeless.</pre>
<pre>however, the dxf file has been designed to be easy to process by program,
not manually. the format was constructed with the deliberate intention of
making it easy to ignore information you don't care about while easily
reading the information you need. just remember to handle the groups in
any order and ignore any group you don't care about, and you'll be home
free.</pre>
<pre>as an example, the following is a microsoft basic program that reads a dxf
file and extracts all the line entities from the drawing (ignoring lines
that appear inside blocks). it prints the endpoints of these lines on the
screen. as an exercise you might try entering this program into your com-
puter, running it on a dxf file from one of your drawings, then enhancing
it to print the center point and radius of any circles it encounters. this
program is not put forward as an example of clean programming technique nor
the way a general dxf processor should be written; it is presented as an
example of just how simple a dxf-reading program can be.</pre>
<pre> 1000 rem
1010 rem extract lines from dxf file
1020 rem
1030 g1% = 0
1040 line input "dxf file name: "; a$
1050 open "i", 1, a$ + ".dxf"
1060 rem
1070 rem ignore until section start encountered
1080 rem
1090 gosub 2000
1100 if g% <> 0 then 1090
1110 if s$ <> "section" then 1090
</pre>
<pre>20
 (c) drawing interchange and file formats</pre>
<pre> 1120 gosub 2000
1130 rem
1140 rem skip unless entities section
1150 rem
1160 if s$ <> "entities" then 1090
1170 rem
1180 rem scan until end of section, processing lines
1190 rem
1200 gosub 2000
1210 if g% = 0 and s$ = "endsec" then 2200
1220 if g% = 0 and s$ = "line" then gosub 1400 : goto 1210
1230 goto 1200
1400 rem
1410 rem accumulate line entity groups
1420 rem
1430 gosub 2000
1440 if g% = 10 then x1 = x : y1 = y : z1 = z
1450 if g% = 11 then x2 = x : y2 = y : z2 = z
1460 if g% = 0 then print "line from (";x1;",";y1;",";z1;") to (";x2;
",";y2;",";z2;")
1470 goto 1430
2000 rem
2010 rem read group code and following value
2020 rem for x coordinates, read y and possibly z also
2030 rem
2040 if g1% < 0 then g% = -g1% : g1% = 0 else input #1, g%
2050 if g% < 10 or g% = 999 then line input #1, s$ : return
2060 if g% >= 38 and g% <= 49 then input #1, v : return
2080 if g% >= 50 and g% <= 59 then input #1, a : return
2090 if g% >= 60 and g% <= 69 then input #1, p% : return
2100 if g% >= 70 and g% <= 79 then input #1, f% : return
2110 if g% >= 210 and g% <= 219 then 2130
2120 if g% >= 20 then print "invalid group code";g% : stop
2130 input #1, x
2140 input #1, g1%
2150 if g1% <> (g%+10) then print "invalid y coord code";g1% : stop
2160 input #1, y
2170 input #1, g1%
2180 if g1% <> (g%+20) then g1% = -g1% else input #1, z
2190 return
2200 close 1</pre>
<pre>writing a program that constructs a dxf file is more difficult, because you
must maintain consistency within the drawing in order for autocad to find
it acceptable. autocad allows you to omit many items in a dxf file and
still obtain a usable drawing. the entire header section can be omitted if
you don't need to set any header variables. any of the tables in the
tables section can be omitted if you don't need to make any entries, and in
fact the entire tables section can be dropped if nothing in it is required.
if you define any linetypes in the ltype table, this table must appear
before the layer table. if no block definitions are used in the drawing,
the blocks section can be omitted. if present, however, it must appear
before the entities section. within the entities section, you can refer-
ence layer names even though you haven't defined them in the layer table.</pre>
<pre> 21
autocad reference manual</pre>
<pre>such layers will be automatically created with color 7 and the continuous
linetype. the eof item must be present at the end of file.</pre>
<pre>the following microsoft basic program constructs a dxf file representing a
polygon with a specified number of sides, leftmost origin point, and side
length. this program supplies only the entities section of the dxf file,
and places all entities generated on the default layer "0". this may be
taken as an example of a minimum dxf generation program. since this pro-
gram doesn't create the drawing header, the drawing limits, extents, and
current view will be invalid after performing a dxfin on the drawing gener-
ated by this program. you can do a "zoom e" to fill the screen with the
drawing generated. then adjust the limits manually.</pre>
<pre> 1000 rem
1010 rem polygon generator
1020 rem
1030 line input "drawing (dxf) file name: "; a$
1040 open "o", 1, a$ + ".dxf"
1050 print #1, 0
1060 print #1, "section"
1070 print #1, 2
1080 print #1, "entities"
1090 pi = atn(1) * 4
1100 input "number of sides for polygon: "; s%
1110 input "starting point (x,y): "; x, y
1120 input "polygon side: "; d
1130 a1 = (2 * pi) / s%
1140 a = pi / 2
1150 for i% = 1 to s%
1160 print #1, 0
1170 print #1, "line"
1180 print #1, 8
1190 print #1, "0"
1200 print #1, 10
1210 print #1, x
1220 print #1, 20
1230 print #1, y
1240 print #1, 30
1250 print #1, 0.0
1260 nx = d * cos(a) + x
1270 ny = d * sin(a) + y
1280 print #1, 11
1290 print #1, nx
1300 print #1, 21
1310 print #1, ny
1320 print #1, 31
1330 print #1, 0.0
1340 x = nx
1350 y = ny
1360 a = a + a1
1370 next i%
1380 print #1, 0
1390 print #1, "endsec"</pre>
<pre>22
 (c) drawing interchange and file formats</pre>
<pre> 1400 print #1, 0
1410 print #1, "eof"
1420 close 1</pre>
<pre>the dxfin command is relatively forgiving with respect to the format of
data items. as long as a properly formatted item appears on the line on
which the data is expected, dxfin will accept it (of course, string items
should not have leading spaces unless these are intended to be part of the
string). the above program takes advantage of this flexibility in input
format, and does not go to great effort to generate a file appearing
exactly like one generated by autocad.</pre>
<pre>in the case of error loading a dxf file using dxfin, autocad reports the
error with a message indicating the nature of the error detected and the
last line processed in the dxf file before the error was detected. this
may not be the line on which the error occurred, especially in the case of
such errors as omission of required groups.
</pre>
<pre>c.2 binary drawing interchange files</pre>
<pre>the ascii dxf file format described in the preceding sections of this
appendix is a complete representation of an autocad drawing in an ascii
text form easily processed by other programs. in addition, autocad can
produce or read a binary form of the full dxf file, and accepts limited
input in another binary file format. these binary files are described in
the following sections.
</pre>
<pre>c.2.1 binary dxf files</pre>
<pre>the dxfout command provides a "binary" option that writes binary dxf files.
such a file contains all of the information present in an ascii dxf file,
but in a much more compact form that takes, typically, 25% less file space
and can be read and written more quickly (typically 5 times faster) by
autocad. unlike ascii dxf files, which entail a trade-off between size and
floating-point accuracy, binary dxf files preserve all of the accuracy in
the drawing database. autocad release 10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -