AutoCAD DXF

Also Known As:

AutoCAD Drawing Interchange Format, DXF, .DXB, .SLD, .ADI


Type Vector
Colors 256
Compression None
Maximum Image Size NA
Multiple Images Per File No
Numerical Format Multiple
Originator Autodesk
Platform MS-DOS
Supporting Applications AutoCAD, many CAD programs, CorelDraw!, others
See Also None

Usage
Storage and exchange of CAD and vector information.

Comments
A difficult format, mainly because it can contain so many different types of data. The format is controlled and defined by Autodesk for use in its CAD program AutoCAD. The most common form of DXF is 7-bit text, but there are also two related binary formats, one that also uses the DXF extension and another that uses the DXB extension.

Vendor specifications are available for this format.

Code fragments are available for this format.


The AutoCAD DXF (Drawing Interchange Format) and the AutoCAD DXB (Drawing Interchange Binary) formats are associated with the CAD application AutoCAD, created and maintained by Autodesk. DXB is a simplified binary version of a DXF file. Other file formats associated with AutoCAD are the slide (.SLD) and plot (.ADI) formats.

Contents:
File Organization
File Details
For Further Information

Although DXF was developed to represent the data used in a CAD program, it is used by many programs as a "least common denominator" format for the exchange of many different types of data, most commonly vector-oriented information but also text and 3D polygons. As a CAD format, it can also express common drafting concepts such as associative dimensions.

Almost any type of data can be represented somehow in DXF. For example, a drawing program like CorelDraw! exports the outlines of the drawing with the AutoCAD POLYLINE entity, while a 3D program might only export 3DFACE entities representing three- and four-sided polygons. DXF also allows a perplexing number of ways of doing nearly the same thing, such as describing objects as separate editable groups. One program might place the objects on different layers of the drawing, while another might use different pen colors, while a third might use named "blocks" to group the data.

Although DXF is widely used for the exchange of simple line data, an application designer wishing to support DXF must consider that AutoCAD can store these many types of data in different ways.

Sometimes the correct interpretation of a DXF file can be very difficult. The intended appearance of lines and regions can be dependent on many seemingly obscure settings in the header of the DXF file. Because DXF files are so difficult to faithfully interpret, many application designers decide to only export DXF.

Even among programs that claim to import DXF, you may find they only support a subset of everything that is possible in DXF. If you hope to create your own DXF files in order to transfer data into a program that claims to import DXF, be sure you know which representations it understands.

With each new version of AutoCAD, DXF changes. AutoCAD Release 13 expanded the DXF format in many ways in order to represent the specialized data of a new geometry engine. These additions store the complex surface and solid information for Spatial Technology's ACIS geometry engine, now a part of AutoCAD. Not all of this information has been documented and must be skipped by any DXF reader. With Release 13, AutoCAD's own tolerance for minimal DXF files changed, too, as it expanded an auditing step that checks the validity of the DXF files it imports.

Obviously, the DXF file format is quite complex and subtle. Because it would take more than 50 pages to fully document every possible part of this format, we will simply outline the basic structure of any DXF file. For full details, refer to Autodesk's specification document on the CD-ROM.

File Organization

A DXF file consists of up to seven sections: a header, tables, blocks, classes, objects, entities, and an end-of-file marker.

File Details

A DXF file is composed of pairs of group codes and associated values. Each occurs on its own line in the text file. The integer group code indicates the type of the value to follow. Group codes occur in ranges. For example, group codes 0 to 9 are followed by strings, and each different group code is used in certain situations. Group code 0 indicates the start of an entity, table or end-of-file indicator. Code 1 indicates the primary text value for an entity. Group code 2 is used for names, such as names of sections, blocks, table names, etc. Code 9 introduces the name of a header section variable. For example, at the start of every DXF file, group code 0 precedes the SECTION command, followed by group code 2 with a string indicating the type of section, such as HEADER:

  0
SECTION
  2
HEADER
  9
$ACADVER
  1
AC1012

Ranges of group codes indicate the type of data to follow. Group codes 10 to 59 are used for floating-point values, such as point coordinates. Codes 60 to 79 store integer values. For example, to store a 2D point location, first group code 10 is used for the X value, then code 20 is used for the Y value. If the entity has a secondary coordinate value, it would also use group codes 11 and 21. Here is a minimal yet complete DXF file that describes a line from location (1,2) to (3,4):

0
SECTION
  2
ENTITIES
999
This is just a line.
  0
LINE
  8
0
 10
1.0
20
2.0
11
3.0
21
4.0
  0
ENDSEC
  0
EOF

Group code 999 precedes a comment. This line will be placed on layer 0, as indicated by group code 8. This minimal file is an example of an "entities only" file that will be accepted by almost any program that claims to import DXF.

As AutoCAD is expanded with each new version, new group codes are added. If you are writing a program that reads DXF files, you can ensure future compatibility by ignoring undefined group code and value pairs.

One curious aspect of DXF is that it does not contain a color palette, yet most objects in a DXF file can be assigned a distinct color value with group code 62. Each drawing entity can be assigned a number from 1 to 255 known as an AutoCAD Color Index, or ACI, also described in earlier documentation as a "pen number." This reflects AutoCAD's origins as a CAD package where drawings were typically printed by a pen plotter that had several ink pens but with no standard correspondence to actual RGB values, or even to the colors of the lines on the screen. AutoCAD now sets a default RGB color for each ACI when it appears onscreen, but these are not stored in the DXF file.

Binary DXF

The most commonly used form of DXF is stored in 7-bit ASCII characters, but a binary format also uses the extension DXF. AutoCAD Release 10 was the first to support binary DXF. Binary DXF files are usually 20 to 30 percent smaller than the ASCII version, and they load more quickly into AutoCAD.

Binary DXF files always begin with a specific 22-byte identification string:

AutoCAD Binary DXF<0Dh><0Ah><1Ah><00h>

Binary DXF uses group-value pairs, too. Group codes are usually one byte, followed by either a two-byte little-endian integer, an eight-byte IEEE floating-point double value, or a zero-terminated string, depending on the type of value associated with the group code's range. To represent group codes greater than 254, the value 255 precedes a two-byte integer group code.

A third form of DXF known as DXB is an even simpler binary format. DXB files are even smaller than the binary DXF format. DXB files are limited to a small set of entities such as line, point, circle, arc, trace, solid, polyline, and 3D face. Entities are indicated by their own byte code and are immediately followed by the necessary data for that entity, in an appropriate integer or floating-point format.

A DXB file can be distinguished from a binary DXF file by the file extension .DXB and by the fact that it always begins with a 19-byte identification string:

AutoCAD DXB 1.0<0Dh><0Ah><1Ah><00h>

For Further Information

For further information about the AutoCAD DXF format, see the DXF specification included on the CD-ROM.

The AutoCAD Manual Release 12 also contains complete information on the DXF format; see:

AutoCAD Customization Manual, Release 12, Autodesk Inc., 1992, pp. 241-281.

AutoCAD Developer's Guide, Release 13, Autodesk Inc., 1995, pp. 505-556.

Autodesk has also released an electronic document describing the DXF format, which may be found on many online services and BBSs.

Many books on AutoCAD have been published, and several include in-depth information on the DXF format, including the following:

Jones, Frederick H. and Lloyd Martin, The AutoCAD Database Book, Ventana Press, Chapel Hill, NC, 1989.

Johnson, N., AutoCAD, The Complete Reference, second edition, McGraw-Hill, New York, NY, 1991.

For additional information about this format, you may also contact:

Autodesk, Inc.
Attn: Neele Johnston
Autodesk Developer Marketing
2320 Marinship Way
Sausalito, CA 94965
Voice: 415-491-8719
Email: neele@autodesk.com
WWW: http://www.autodesk.com/



Copyright © 1996, 1994 O'Reilly & Associates, Inc. All Rights Reserved.

Hosted by uCoz