[solved] Writing XDATA accepted by QCAD/CAM

Use this forum to ask questions about how to do things in dxflib.

Moderator: andrew

Post Reply
weze
Newbie Member
Posts: 6
Joined: Mon May 25, 2020 11:30 am

[solved] Writing XDATA accepted by QCAD/CAM

Post by weze » Fri Mar 26, 2021 10:08 am

I know that the current DXF-Lib version (3.17.0) doesn't support writing XDATA (see https://qcad.org/rsforum/viewtopic.php? ... data#p9180). We are using the nesting functionality of QCAD/CAM and for some extent we have to supply the drawing entities we want to be nested with some app specific extra data. So I tried to implement the XDATA writing outside DXF lib in our code. Every time I write a drawing entity, I append a XDATA section before ending the entity in the way like (using export version

Code: Select all

DL_Codes::AC1015
for writing):

Code: Select all

	...
	m_dxf.writePolyline(*dw, polyline, m_cAtttribute);
	DL_VertexData vertex;
	....
	// adding the vertex data
	....
	// write entity ID
	dw->dxfString(1001, "digMAR");	//starts extended data section
	dw->dxfString(1000, str.toStdString());

	m_dxf.writePolylineEnd(*dw);
As the DXF format reference suggests, our APP ID is registered in a seperate TABLE section directly after the HEADER section and before the ENTITY section:

Code: Select all

	...
	dw->sectionTables();	// start tables section

//	// register our APP-ID
	dw->tableAppid(1);	// start registered APPID table
	d->m_dxf.writeAppid(*dw, "digMAR");
	dw->tableEnd();   // table end
	dw->sectionEnd();
	...
This results in a DXF file as expected with an XDATA section at the end of each drawing entity and an app register section after the HEADER (see the attached "id_test.dxf" file which contains 1 polyline entity representing an arc).
The import into QCAD only works with the file type "DXF Files [dxflib]", the import with file type "All CAD Files [OpenDesign]" results in an import error. But with the [dxflib] import the XDATA is obviously ignored (the XDATA is not displayed in the "Custom" section of the proeprty editor), and after saving back the drawing by QCAD, the APP ID registering and the entity XDATA has been removed from the DXF file (see attached "id_test_qcad.dxf")

So my question is if there exists a possibility with dxflib to write entity XDATA in a way that QCAD accepts it and keeps it also when the DXF file is saved back again by QCAD? If yes, how has the written data to be structured?

Thanks in advance for any help!
Attachments
id_test_qcad.dxf
(28.07 KiB) Downloaded 503 times
id_test.dxf
(1.6 KiB) Downloaded 505 times

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

Re: Writing XDATA accepted by QCAD/CAM

Post by andrew » Fri Mar 26, 2021 10:26 am

The DXF file id_test.dxf is not valid as it is not complete (no layers, no linetypes, ...). Unfortunately, DXF is a very unforgiving format. dxflib is more forgiving, even with invalid files.

Please have a look at this thread for a complete example of writing a valid DXF file:
viewtopic.php?f=21&t=823&p=8942#p8942

Also, your App ID must be "QCAD" for QCAD/CAM to try to understand the XData at all.

weze
Newbie Member
Posts: 6
Joined: Mon May 25, 2020 11:30 am

Re: Writing XDATA accepted by QCAD/CAM

Post by weze » Fri Mar 26, 2021 11:51 am

...perfect, creating a valid DXF file following your suggestion solved the issue! The XDATA is displayed and kept correctly in QCAD even with our custom APPID.

Thanks a lot!!
regards
Werner

Post Reply

Return to “dxflib 'How Do I' Questions”