📄 dxf.txt
字号:
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
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.
21
AutoCAD Reference Manual
Such layers will be automatically created with color 7 and the CONTINUOUS
linetype. The EOF item must be present at the end of file.
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.
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"
22
(C) Drawing Interchange and File Formats
1400 PRINT #1, 0
1410 PRINT #1, "EOF"
1420 CLOSE 1
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.
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.
C.2 Binary Drawing Interchange Files
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.
C.2.1 Binary DXF Files
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 is the first version to support
this form of DXF file; it cannot be read by older versions.
A binary DXF file begins with a 22-byte sentinel consisting of:
"AutoCAD Binary DXF<CR><LF><SUB><NUL>"
Following the sentinel are (group,value) pairs as in an ASCII DXF file, but
represented in binary form. The group code is a single-byte binary value,
and the value that follows is one of the following:
o a two-byte integer with the least significant byte first and the
most significant byte last,
23
AutoCAD Reference Manual
o an eight-byte IEEE double precision floating-point number stored
with the least significant byte first and the most significant
byte last, or
o an ASCII string terminated by a zero (NUL) byte.
The type of the datum following a group is determined from the group code
according to the same rules used in decoding ASCII DXF files. Translation
of angles to degrees, and dates to fractional Julian date representation,
is performed for binary files as well as for ASCII DXF files. The comment
group, 999, is not used in binary DXF files.
DXFOUT writes binary DXF files with the same file type (".dxf") as for
ASCII DXF files. The DXFIN command automatically recognizes a binary file
(by means of its sentinel string) and loads it. There is no need for you
to identify it as a binary file.
If DXFIN encounters an error in a binary DXF file, it reports the byte
address within the file where the error was detected.
C.3 Binary Drawing Interchange (DXB) Files
The DXF file formats described earlier in this appendix are complete repre-
sentations of an AutoCAD drawing that can be written and read by AutoCAD
and other programs. However, AutoShade(tm) and programs executed via the
"external commands" facility (Appendix B) often have a need to supply
simple geometric input to AutoCAD. For these purposes, another file format
even more compact than the binary DXF format is supported. This format,
called DXB (for "drawing interchange binary") is limited in the entities it
can represent. Furthermore, AutoCAD has a command to read such files, but
no direct method of writing them. (The ADI plotter driver can plot to a
file in DXB format.)
C.3.1 DXBIN Command
To load a DXB file produced by a program such as AutoShade, enter the DXBIN
command:
Command: DXBIN
DXB file:
enter the name of the file you wish to load. Don't include a file type;
".dxb" is assumed.
24
(C) Drawing Interchange and File Formats
C.3.2 DXB File Format
This information is for experienced programmers, and is subject to change
without notice.
The format of a DXB file is as follows:
Header: "AutoCAD DXB 1.0" CR LF ^Z NUL (19 bytes)
Data: . . . Zero or more data records . . .
Terminator: NUL (1 byte)
Each data record begins with a single byte giving its type, followed by
data items. The data items have various forms of representation and encod-
ing. In the descriptions below, each data item is prefixed with a letter
and a hyphen. The meaning of the letter codes is as follows:
w- 16-bit integer, byte reversed in the standard 8086 style (least
significant byte first, most significant byte second).
f- IEEE 64-bit floating-point value stored with lsb first, msb last
(as stored by an 8087).
l- 32-bit integer with the bytes reversed 8086-style.
n- Number which may be either a 16-bit integer or a floating-point
number depending on the most recent setting of the "number mode"
data item. The number mode defaults to 0, signifying integers. If
set to 1, all n- items will be read as floating-point.
u- Item which is either a 32-bit integer or a floating-point number
depending on the most recent number mode setting. If a 32-bit
integer, the value is scaled by multiplying it by 65536 (2^16). If
a floating-point value, no scaling is applied.
a- Item representing an angle. If number mode is integer, this is a
32-bit integer representing an angle in units of millionths of a
degree (range 0 to 360,000,000). If a floating-point number, rep-
resents degrees.
In the following table, the lengths include the item-type byte and assume
the number mode is set to zero (integer mode). If number mode is floating-
point, add 6 bytes to the length for each n- item present and 4 bytes for
each a-, or u- item present.
Item type Code Data items Length
(decimal) (bytes)
LINE 1 n-fromx n-fromy 9
n-tox n-toy
POINT 2 n-x n-y 5
CIRCLE 3 n-ctrx n-ctry n-rad 7
ARC 8 n-ctrx n-ctry n-rad 19
a-starta a-enda
continued ...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -