DXF File - Won't Open in Autodesk Viewer
Asked Answered
T

4

7

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
Tamas answered 21/5, 2015 at 19:32 Comment(4)
Since you are asking about your file not being read (and not about errors or issues in your code), seems like this might be off-topic for this site.Assimilative
Well, I think it's not being read due to an error or something omitted from my code. That's why I'm looking for help here.Tamas
How are we to tell if you have an error or something omitted from your code without seeing the code?Harrold
What I pasted above is my code... that's what I'm trying validate, that my DXF format is correct.Tamas
S
5

A couple of issues with your DXF file.

  1. 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.

  2. 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.

Spillman answered 26/5, 2015 at 18:15 Comment(1)
If I could accept this answer 10 times I would. Thanks so much for your help.Tamas
F
2

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.

Flagstone answered 21/5, 2015 at 23:49 Comment(1)
I tried taking all the 30 codes out and it still won't open. I figured it was being particular, but it's really hard to figure out what's wrong when they provide no useful error feedback!Tamas
F
1

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.

Fiscus answered 22/5, 2015 at 14:11 Comment(2)
I don't have AutoCAD, which is the main problem. I have a few sample files I was given, but they're thousands of lines long and not great for comparison.Tamas
If is a quick test, what about the trial version (for 30 days)? Or try the AutoCAD I/O, which is a webservice that still free of charge (as of May/2015), check at developer.autodesk.comFiscus
B
0

Well your question is specific to particular data format problem in DXF which is missing/adding some values that AutoCad is not happy about. Your best chance to resolve this is try creating a similar file from the AutoCad and compare what you might have missed/added wrongly. Very difficult for others to debug for you in this situation. I have seen the DXF specifications pdfs from Autocad, have some writing DXF file help sections in the bottom, refer to them too.

Besprent answered 13/8, 2015 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.