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.
According to the official DXF spec from Autodesk (PDF here), the vertices of an LWPOLYLINE are 2D-only; e.g., they should only have 10
and 20
codes and NOT any 30
codes and since all of your 30
codes are 0.0
it shouldn't make a difference. If you do decide that the LWPOLYLINE needs to have Z-values other than zero, you can specify a code 38
pair (elevation) before your first 10
code pair.
If you need different Z-values for each point consider using POLYLINE with many VERTEX entities followed by a single SEQEND.
EDIT: While the DXF spec is supposed to be very free-form, I've found that the Autodesk implementation of it is very particular about what it can read.
Indeed the LWPOLYLINE is 2D only...
One more suggestions: go on AutoCAD and create a drawing similar to that, then export as DXF, that way you can compare with what you're designing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With