# Spline weights are not read from DXF file.

**URL:** http://forum.qcad.org/t/spline-weights-are-not-read-from-dxf-file/583
**Category:** dxflib Troubleshooting and Problems
**Created:** [November 9, 2011, 5:33pm UTC](http://forum.qcad.org/t/spline-weights-are-not-read-from-dxf-file/583 "2011-11-09T17:33:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![beding](http://forum.qcad.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@beding](http://forum.qcad.org/u/beding)
#### Post date: [November 9, 2011, 5:33pm UTC](http://forum.qcad.org/t/spline-weights-are-not-read-from-dxf-file/583/1 "2011-11-09T17:33:49Z")

</div>

Why are they not read?  
Can you tell me ho to add code to read the weights?  
Regards,  
Bert

---

<div class="post-metadata">

### Author: ![andrew](http://forum.qcad.org/user_avatar/forum.qcad.org/andrew/32/7_2.png) [@andrew](http://forum.qcad.org/u/andrew)
#### Post date: [November 27, 2011, 10:04pm UTC](http://forum.qcad.org/t/spline-weights-are-not-read-from-dxf-file/583/2 "2011-11-27T22:04:28Z")

</div>

This patch should do it:

```plaintext
Index: dl_dxf.cpp
--- dl_dxf.cpp	(revision 19810)
+++ dl_dxf.cpp	(working copy)
@@ -56,9 +56,11 @@
     maxKnots = 0;
     knotIndex = 0;
 
+ weights = NULL;
     controlPoints = NULL;
     maxControlPoints = 0;
     controlPointIndex = 0;
+ weightIndex = 0;
 
     leaderVertices = NULL;
     maxLeaderVertices = 0;
@@ -88,6 +90,9 @@
     if (controlPoints!=NULL) {
         delete[] controlPoints;
     }
+ if (weights!=NULL) {
+ delete[] weights;
+ }
     if (leaderVertices!=NULL) {
         delete[] leaderVertices;
     }
@@ -941,7 +946,8 @@
     for (i=0; i<maxControlPoints; i++) {
         DL_ControlPointData d(controlPoints[i*3],
                               controlPoints[i*3+1],
- controlPoints[i*3+2]);
+ controlPoints[i*3+2], 
+ weights[i]);
 
         creationInterface->addControlPoint(d);
     }
@@ -1218,21 +1224,27 @@
         return true;
     }
 
- // Allocate Spline control points (group code 73):
+ // Allocate Spline control points / weights (group code 73):
     else if (groupCode==73) {
         maxControlPoints = toInt(groupValue);
         if (maxControlPoints>0) {
             if (controlPoints!=NULL) {
                 delete[] controlPoints;
             }
+ if (weights!=NULL) {
+ delete[] weights;
+ }
             controlPoints = new double[3*maxControlPoints];
+ weights = new double[maxControlPoints];
             for (int i=0; i<maxControlPoints; ++i) {
                 controlPoints[i*3] = 0.0;
                 controlPoints[i*3+1] = 0.0;
                 controlPoints[i*3+2] = 0.0;
+ weights[i] = 1.0;
             }
         }
         controlPointIndex=-1;
+ weightIndex=-1;
         return true;
     }
 
@@ -1259,6 +1271,19 @@
         }
         return true;
     }
+
+ // Compute spline weights (group code 41)
+ else if (groupCode==41) {
+
+ if (weightIndex<maxControlPoints-1) {
+ weightIndex++;
+ }
+
+ if (weightIndex>=0 && weightIndex<maxControlPoints) {
+ weights[weightIndex] = toReal(groupValue);
+ }
+ return true;
+ }
     return false;
 }
 
Index: dl_dxf.h
--- dl_dxf.h	(revision 19810)
+++ dl_dxf.h	(working copy)
@@ -379,9 +379,11 @@
     int maxKnots;
     int knotIndex;
 	
+ double* weights;
     double* controlPoints;
     int maxControlPoints;
     int controlPointIndex;
+ int weightIndex;
 
     double* leaderVertices;
     int maxLeaderVertices;
Index: dl_entities.h
--- dl_entities.h	(revision 19810)
+++ dl_entities.h	(working copy)
@@ -442,10 +442,11 @@
      * Constructor.
      * Parameters: see member variables.
      */
- DL_ControlPointData(double px, double py, double pz) {
+ DL_ControlPointData(double px, double py, double pz, double weight) {
         x = px;
         y = py;
         z = pz;
+ w = weight;
     }
 
     /*! X coordinate of the control point. */
@@ -454,6 +455,8 @@
     double y;
     /*! Z coordinate of the control point. */
     double z;
+ /*! Weight of control point. */
+ double w;
 };

```
