0

I would like to convert the drawings inside a .dxf file into g-code. There are tools doing that but I would like to code it myself. So, the very first part is to decode the .dxf format.

I downloaded a .dxf file here and opened it in a "text editor". I am also referring to this manual. It looks like what is inside a .dxf file is mostly style and configuration information and I tend to omit almost everything.

The actual information about the coordinates seems to be at the SECTION of ENTITIES. I am copy-pasting this section below. There are two LWPLOYLINES where 10 represents X positions and 20 represents Y positions of the vertices. 42 represents some information about bulge in the figure.

The question is, what should I take into consideration -other than the coordinates- while converting the dxf format into G-code? Also, I don't know where this information is stored in a dxf file.

What comes to my mind are:

  1. Units, i.e. meters, millimeters, inches
  2. Offset, i.e. according to (0,0) point
  3. Scale ratio, i.e 1:8, 1:100 etc.

So, what fields should I know to be able to obtain an accurate G-code from the dxf file and where are these fields located inside the file? Thank you.


  0
SECTION
  2
ENTITIES
  0
LWPOLYLINE
  5
72
330
1F
100
AcDbEntity
  8
Layer 1
100
AcDbPolyline
 90
       12
 70
     1
 43
0.0
 10
11.7511418685121
 20
14.9867256637168
 42
1.0
 10
3.31114186851211
 20
14.9867256637168
 10
-0.0132743362831871
 20
14.9867256637168
 10
-0.0132743362831871
 20
11.72
 42
1.0
 10
-0.0132743362831871
 20
3.28
 10
-0.0132743362831871
 20
0.0398230088495577
 10
3.28
 20
0.039823008849557
 42
1.0
 10
11.72
 20
0.0398230088495577
 10
15.0132743362832
 20
0.0398230088495577
 10
15.0132743362832
 20
3.28
 42
1.0
 10
15.0132743362832
 20
11.72
 10
15.0132743362832
 20
14.9867256637168
  0
LWPOLYLINE
  5
73
330
1F
100
AcDbEntity
  8
Layer 1
100
AcDbPolyline
 90
       12
 70
     1
 43
0.0
 10
12.6544611051008
 20
15.9867256637168
 10
16.0132743362832
 20
15.9867256637168
 10
16.0132743362832
 20
12.6233192365887
 42
-0.823684764724874
 10
16.0132743362832
 20
2.37668076341128
 10
16.0132743362832
 20
-0.960176991150442
 10
12.6233192365887
 20
-0.960176991150442
 42
-0.823684764724874
 10
2.37668076341128
 20
-0.960176991150443
 10
-1.01327433628319
 20
-0.960176991150442
 10
-1.01327433628319
 20
2.37668076341128
 42
-0.823684764724874
 10
-1.01327433628319
 20
12.6233192365887
 10
-1.01327433628319
 20
15.9867256637168
 10
2.40782263192339
 20
15.9867256637168
 42
-0.823684764724874
  0
ENDSEC

Related Questions

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Xfce4
  • 557
  • 5
  • 28
  • I don't know what g-code is so I can't comment on that. But keep in mind that it is not as simple as reading the coordinates. Some entities are referred to a **planer** and as a result have had their coordinates transformed. You need to identify in the first instance if 'LWPOLYLINE' does planar coordinates (referred to a OCS coordinates in the DXF manual). If so, then you need to transform them into WCS (world coordinates) to know the real X/Y/Z value. This is not a trivial task and the DXF libraries out there most likely cope with this task. Why not use a DXF lib reader? – Andrew Truckle Aug 29 '21 at 08:07
  • Also, you have multiple questions in one again and you really need to limit each question topic for discussion. – Andrew Truckle Aug 29 '21 at 08:11
  • 1
    This might help for the working units: https://stackoverflow.com/a/21168970/2287576 – Andrew Truckle Aug 29 '21 at 08:12
  • @AndrewTruckle G-code is the programming language that most CNC machines use. It is more like a set of instructions performed in the given order with the values provided. [Here](https://en.wikipedia.org/wiki/G-code#List_of_G-codes_commonly_found_on_FANUC_and_similarly_designed_controls_for_milling_and_turning) are some instructions. – Xfce4 Aug 29 '21 at 19:43
  • 1
    What I want to do is to transform the coordinates in the drawing (dxf file) into real life so that the CNC machine can process the material by the true dimensions. – Xfce4 Aug 29 '21 at 19:53
  • I see. I wrote some tools called CutTools for someone. I know he uses those DXF files with CNC machines for making cardboard boxes. – Andrew Truckle Aug 29 '21 at 20:42
  • 1
    Transforming coordinates is not an existing ask. You need a world coordinate matrix. See this: https://math.stackexchange.com/questions/1602827/answered-transformation-between-autocad-ocs-and-wcs-coordinate-systems – Andrew Truckle Aug 29 '21 at 20:43
  • @AndrewTruckle If you wrote CutTools then you should know some about G-code. Maybe you know it by an alternative name like NC-Code. – Xfce4 Aug 29 '21 at 23:07
  • 1
    @AndrewTruckle I checked about OCS, UCS, DCS and WCS. I am not sure if I understand all of them correctly but it looks like I don't need WCS for cutting purposes. OCS will do better. Because all the objects in the drawing will be isolated and their images will be placed on the plate in a way to minimize the material (i.e. steel) used. – Xfce4 Aug 29 '21 at 23:37
  • 1
    The tools I wrote were in c# and ran inside Bricscad on the drawing. Not the same. See: https://www.trucklesoft.co.uk/cut-tools-software-suite/ – Andrew Truckle Aug 30 '21 at 05:55
  • 1
    @AndrewTruckle Your software looks cool. Did you write it alone? How long did it take? – Xfce4 Aug 31 '21 at 01:59
  • I wrote it alone bit by bit. I have a customer who needs the tools for his business purposes and he comes forward with the ideas. – Andrew Truckle Aug 31 '21 at 06:14

0 Answers0