Saving POLYLINE vertices

If you are having problems with dxflib, post here. Please report bugs here.

Moderator: andrew

Post Reply
Aranda
Newbie Member
Posts: 4
Joined: Wed Sep 17, 2008 4:44 am
Location: Perth Australia

Saving POLYLINE vertices

Post by Aranda » Wed Sep 17, 2008 5:24 am

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

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Post by andrew » Wed Sep 17, 2008 9:55 am

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.

Aranda
Newbie Member
Posts: 4
Joined: Wed Sep 17, 2008 4:44 am
Location: Perth Australia

Post by Aranda » Wed Sep 17, 2008 10:02 am

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.entity("VERTEX");
        //dw.entityAttributes(attrib);
    	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);
        }
    }
}
Cheers,
Aranda

Post Reply

Return to “dxflib Troubleshooting and Problems”