Search code examples
autocaddxfcnc

DXF file is not being imported correctly due to arcs & lines not connecting


Our application generates a custom DXF file for glass CNC machines. We have an issue with some of our DXF files not importing correctly into certain program such as AutoCAD, DWG Fastview and others. It does import correctly into other programs. The glass panel has lines and arcs but for some reason these do not form a "continuous line" and we do not know how to resolve this issue.

This is a correct DXF import into ABViewer

This is an incorrect import

Here is the DXF file contents.

0
SECTION
2
HEADER
9
$DIMTXT
40
0.8125
9
$DIMLUNIT
70
5
9
$DIMSTYLE
2
$STANDARD
9
$INSUNITS
70
1
9
$MEASUREMENT
70
0
0
ENDSEC
0
SECTION
2
TABLES
0
ENDSEC
0
SECTION
2
BLOCKS
0
ENDSEC
0
SECTION
2
ENTITIES
0
LINE
5
201
100
AcDbEntity
8
0
100
AcDbline
10
0
20
0
11
29.4375
21
0
0
CIRCLE
5
202
100
AcDbEntity
8
0
100
AcDbCircle
10
26.4375
20
32
40
0.25
0
CIRCLE
5
203
100
AcDbEntity
8
0
100
AcDbCircle
10
26.4375
20
40
40
0.25
0
LINE
5
204
100
AcDbEntity
8
0
100
AcDbline
10
29.4375
20
0
11
29.4375
21
80.625
0
LINE
5
205
100
AcDbEntity
8
0
100
AcDbline
10
29.4375
20
80.625
11
-0.25
21
80.625
0
LINE
5
206
100
AcDbEntity
8
0
100
AcDbline
10
-0.25
20
80.625
11
-0.229845058133013
21
74.1250312478968
0
LINE
5
207
100
AcDbEntity
8
0
100
AcDbline
10
-0.229845058133013
20
74.1250312478968
11
1.10409513850049
21
74.1291674965685
0
ARC
5
208
100
AcDbEntity
8
0
100
AcDbCircle
10
1.45803442446815
20
74.0052643818026
40
0.374999999999998
100
AcDbArc
50
326.620351000522
51
160.706440127943
0
LINE
5
209
100
AcDbEntity
8
0
100
AcDbline
10
1.77117567581777
20
73.7989453165101
11
1.77841725930295
21
71.4635346425387
0
ARC
5
210
100
AcDbEntity
8
0
100
AcDbCircle
10
1.46656151525803
20
71.2552776020666
40
0.375000000000024
100
AcDbArc
50
199.648881396925
51
33.7349705243599
0
LINE
5
211
100
AcDbEntity
8
0
100
AcDbline
10
1.11339741936218
20
71.1291819186747
11
-0.220542777271327
21
71.125045670003
0
LINE
5
212
100
AcDbEntity
8
0
100
AcDbline
10
-0.220542777271327
20
71.125045670003
11
-0.0294572227286729
21
9.49995432999702
0
LINE
5
213
100
AcDbEntity
8
0
100
AcDbline
10
-0.0294572227286729
20
9.49995432999702
11
1.30448297390483
21
9.50409057866875
0
ARC
5
214
100
AcDbEntity
8
0
100
AcDbCircle
10
1.65842225987249
20
9.38018746390281
40
0.375
100
AcDbArc
50
326.620351000518
51
160.706440127943
0
LINE
5
215
100
AcDbEntity
8
0
100
AcDbline
10
1.97156351122211
20
9.17386839861029
11
1.97880509470729
21
6.83845772463893
0
ELLIPSE
5
216
100
AcDbEntity
8
0
100
AcDbEllipse
10
1.66694935066237
20
6.63020068416683
11
0.375
21
0
40
1
41
3.48453032829999
42
0.588786308713265
0
LINE
5
217
100
AcDbEntity
8
0
100
AcDbline
10
1.31378525476651
20
6.50410500077495
11
-0.0201549418669867
21
6.49996875210322
0
LINE
5
218
100
AcDbEntity
8
0
100
AcDbline
10
-0.0201549418669867
20
6.49996875210322
11
0
21
0
0
ENDSEC
0
EOF

Solution

  • Diagnosis

    Your DXF file has DXF version R12 because in the HEADER section is the header variable $ACADVER not set, which defaults to "AC1009".

    DXF R12 does not support the ELLIPSE entity, therefore CAD applications which are picky about the DXF Standard refuse to load such files like AutoCAD, BricsCAD loads the file but shows the issues you pointed out.

    Your ELLIPSE definition looks OK, but BricsCAD loads the ELLIPSE entity with default values: center is (0, 0), major_axis is (1, 0), ratio is 1.0, start_param is 0 and end_param is 2Pi.

    Solutions

    1. Stick to DXF R12

    Use DXF R12 and approximate the ELLIPSE entity by a POLYLINE. The ELLIPSE in this file could be replaced by an ARC because the ratio of major- to minor axis is 1.0 which is a circular arc.

    Another advantage: you could simplify the DXF output

    • handles are not required
    • subclass markers like (100, AcDbEntity) are not required
    • without BLOCK and TABLE definitions you can write only the ENTITIES section as valid DXF R12 file:
    0
    SECTION
    2
    ENTITIES
    0
    LINE
    8
    0
    10
    0
    11
    0
    20
    1
    21
    1
    0
    ENDSEC
    0
    EOF
    

    2. Use DXF R2000 or later

    Advantage: you can use more entity types like ELLIPSE, SPLINE, HATCH, ... but the file format is more complex and it's too much to change to show this here.

    I documented the minimal requirements for DXF R2000 here: https://ezdxf.mozman.at/docs/dxfinternals/filestructure.html#minimal-dxf-content

    A template for DXF R2000 and later is hosted here: https://github.com/mozman/ezdxf/blob/master/examples_dxf/Minimal_DXF_AC1021.dxf