Export canvas drawing to dwg or dxf

Hello everyone, I would like to know if you can help me with a question. How can I export a Canvas drawing to dwg or dxf format? Does anyone have any programming code examples on this?

Bonjour André,

In my app RealCADD, I export drawing to dxf and, in the past, to dwg with the library of Open Design Alliance.
But because of the price of this library, I abandoned the dwg export.
DXF and DWG formats are complicated because Autodesk use this complexity to have less concurrency.
You can found some informations here : Open Design Alliance
There is also : Libre DWG
If you only want to export to dxf, that will be simpler than import DXF files.

1 Like

Hello Eric. The dxf export (without the other features) would be something that would help me a lot! I would like to see an example of exporting a line of a Canvas drawing from XOJO to dxf, if I see how this is done I can learn to apply it in my program. Thank you for your attention!

The minimal file to write a line in DXF is :

0
SECTION
2
ENTITIES
0
LINE
8
0
10
1.834444
20
5.315479
30
0.0
11
4.656667
21
2.211035
31
0.0
0
ENDSEC
0
EOF

Where 10, 20, 30, 11, 21, 31 indicate the x, y, z of the 2 points of the line.

1 Like

Hi André, what Eric said is absolutely correct: DXF is a very complex format despite being textual. The official specs are available at the Autodesk Help website.

Basically, to describe a simple line segment you need at bare minimum a Header section and an Entities section. The Header describes the information about the contents and the Entities section contains all the vector objects (called “entities”), each - very importantly - with a unique handle.

Each bit of information is described by two lines: the first line is the Group Code (8, 10, 20, etc.) that declares the type of variable that is being entered, and the next line contains the information, that can be a string, integer, double.

So the pseudo-code for a line from 1.5, 3.0 to 4.0, 8.0:
Create the file and open a TextOutputStream

Writeline "  0"
Writeline "LINE"
Writeline "  8"  // this declares the layer name
Writeline "0"  // this is actually a string "0"
Writeline "10"  // X coordinate of the 1st point
Writeline "1.5"
Writeline "20"  // Y coordinate of the 1st point
Writeline "3.0"
Writeline "11"  // X coordinate of the 2nd point
Writeline "4.0"
Writeline "21"  // Y coordinate of the 2nd point
Writeline "8.0"
1 Like

What hasn’t been mentioned yet is that a Canvas has no “Contents” on its own. So you hold some dataset in your project, which you can then draw to the canvas, or export to dxf. You are not exporting the canvas, you’re exporting the commands you used to draw the canvas. (drawline, drawstring, etc.)

1 Like

Hi guys, thanks for the help! Your great comments helped me to have a direction to continue my program.