Creating DXF Spline programmatically

1.4k views Asked by At

I need to create spline programmatically. I've made something like:

0
SECTION
  2
HEADER
  9
$ACADVER
  1
AC1006
  0
ENDSEC
  0
SECTION
  2
TABLES
  0
TABLE
2
LAYER
  0
LAYER
 2
shape
 70
 64
 62
 250
 6
CONTINUOUS
 0
LAYER
 2
holes
 70
 64
 62
 250
 6
CONTINUOUS
 0
ENDTAB
 0
ENDSEC
0
SECTION
2
ENTITIES
0
SPLINE
8
shape
100
AcDbSpline
210
0
220
0
230
1
70
4
71
3
72
11
73
4
74
4
42
0.0000001
43
0.0000001
44
0.0000000001
40
0
40
0
40
0
40
0
40
1
40
1
40
1
40
2
40
2
40
2
40
2
10
0
20
0
30
0
10
100
20
50
30
0
10
40
20
40
30
0
10
15
20
23
30
0
11
0
21
0
31
0
11
200
21
200
31
0
11
80
21
80
31
0
11
432
21
234
31
0
0
ENDSEC
0
EOF

When I'm trying to open it in Autodesk TrueView, I'm getting an error:

Undefined group code 210 for object on line 54. Invalid or incomplete DXF input -- drawing discarded.

Where is the error? When I'm copying just SPLINE section to the DXF generated by AI everything works fine. So I think I need to add something in the header section or something.

3

There are 3 answers

0
mozman On BEST ANSWER

This file is DXF version AC1006 which is older than DXF R12. The SPLINE entity requires at least DXF version AC1012 DXF R13/R14. But with DXF version AC1012 the tag structure of DXF files is changed (OBJECTS and CLASSES sections, SubClassMarkers ...), so just editing the DXF version does not work.

See also: http://ezdxf.readthedocs.io/en/latest/dxfinternals/filestructure.html#minimal-dxf-content

Also the SPLINE entity seems to be invalid, it has no handle (5) and no owner tag (330), and the whole AcDbEntity subclass is missing.

2
Brett Forsgren - MSFT On

You may need to assign a handle to the SPLINE, since you're specifying $ACADVER = AC1018 = AutoCAD 2004 where item handles are required.

Try adding a 5-code pair right before the layer designation, like so, where AAAA is a unique hex-encoded handle:

  0
SPLINE
  5     <-- add these two lines
AAAA    <--
  8
shape
100
AcDbSpline
1
fang On

Your spline is of degree 3 with 11 knots (0, 0,0,0,1,1,1,2,2,2,2) and 4 control points ( (0,0), (100,50),(40,40),(15,23) ). This might be the problem culprit. You should either have 4 control points and 8 knots or 7 control points and 11 knots.