We're building a DXF exporter and from what I've read, this extremely simple file should be valid. We don't have any CAD tools to test with, so I'm very limited in my abilities to debug. This opens fine in the Proficad online viewer but I get an error from the Autodesk viewer, saying "The drawing file is invalid and cannot be viewed".
This is the file in its entirety. Any help is appreciated!
0
SECTION
2
ENTITIES
0
LWPOLYLINE
90
5
70
0
43
0.0
10
-8.75
20
-11.75
30
0.0
10
-8.75
20
11.75
30
0.0
10
8.75
20
11.75
30
0.0
10
8.75
20
-11.75
30
0.0
10
-8.75
20
-11.75
30
0.0
0
ENDSEC
0
EOF
A couple of issues with your DXF file.
LWPOLYLINE requires a bunch of extra overhead to use. You need a TABLES section and then you have to deal with AcDbEntity and AcDbPolyline entries. It gets complicated fast. Switching to the POLYLINE entity will save you a ton of headache.
You need a HEADER section for AutoCAD to open your DXF file. You don't have to put much in the HEADER, basically just version info.
Show below is a minimally functional DXF file (saved in R12 format) that will successfully open in AutoCAD:
0
SECTION
2
HEADER
9
$ACADVER
1
AC1009
0
ENDSEC
0
SECTION
2
ENTITIES
0
POLYLINE
5
7C
8
0
66
1
10
0.0
20
0.0
30
0.0
0
VERTEX
5
174
8
0
10
-8.75
20
-11.75
30
0.0
0
VERTEX
5
175
8
0
10
-17.5
20
0.0
30
0.0
0
VERTEX
5
176
8
0
10
-8.75
20
11.75
30
0.0
0
VERTEX
5
177
8
0
10
0.0
20
0.0
30
0.0
0
VERTEX
5
178
8
0
10
-8.75
20
-11.75
30
0.0
0
SEQEND
5
179
8
0
0
ENDSEC
0
EOF
If this is all you are going to put in your file, it should work just fine. Keep in mind that all DXF entities need a handle (basically an ID number).
0
POLYLINE
5
7C
The 5
above is the code that indicates the handle(ID number) will follow. The 7C
is the actual handle. If you add more entities, you will need to increment the handle for each one, so every entity has a unique handle.