Page 1 of 1

Saving POLYLINE vertices

Posted: Wed Sep 17, 2008 5:24 am
by Aranda
Hi, first up, thankyou for an excellent DXF parsing library. I am currently investigating it's use to load and save DXF files with POLYLINE being the main entity I am concerned with.

Most of the POLYLINE entities i've encountered so far store X, Y and Z components with each VERTEX (or in a list for the LWPOLYLINES). The issue arose when I wrote code to save the DXF. I just output the same structs that were supplied to the DXFLib DL_CreationInterface when it loaded the file. When I tried to reload the saved file, it had lost all of the elevation (ie component 30 of the VERTEXs).

After digging around in the source, I found that DL_Dxf::writeVertex() doesn't actually output the 30 component (not in either of the supported DXF format versions). It was easy enough to fix, but I just wanted to ask if there was a reason for not outputting the 30 component when you do actually read the component?

My reason for asking is that I'd prefer not to modify the DXFLib source, particularly if I end up using it commercially (and hence buying a license).

Posted: Wed Sep 17, 2008 9:55 am
by andrew
It looks indeed like the elevation is not exported. There is no specific reason for this, other than that we simply are not using the elevation in our products. If you send us the patch or changed file(s), we will fix this for future dxflib releases.

Posted: Wed Sep 17, 2008 10:02 am
by Aranda
Thanks for the reply.

Here is the modified function from dl_dxf.cpp:

Code: Select all

 * Writes a single vertex of a polyline to the file.
 * @param dw DXF writer
 * @param data Entity data from the file
 * @param attrib Attributes
void DL_Dxf::writeVertex(DL_WriterA& dw,
                         const DL_VertexData& data) {

    if (version==VER_2000) {
        dw.dxfReal(10, data.x);
        dw.dxfReal(20, data.y);
        dw.dxfReal(30, data.z);  // ADDED THIS LINE
        if (fabs(data.bulge)>1.0e-10) {
            dw.dxfReal(42, data.bulge);
    } else {
    	dw.dxfString(8, polylineLayer);
        dw.coord(VERTEX_COORD_CODE, data.x, data.y, data.z); // ADDED LAST PARAMETER TO THIS LINE
        if (fabs(data.bulge)>1.0e-10) {
            dw.dxfReal(42, data.bulge);