This project has moved and is read-only. For the latest updates, please go here.

DXF code to gcode

Jan 5 at 10:31 AM
Hi there,

I am new to dxf files and would like to understand how a dxf file is understood. I was wondering whether this library could be used to convert a model in dxf to g code for a cnc cutting machine. The g code will be later converted to coordinates needed by the motor controllers to actually cut a material. Any help in that direction will be helpful. For now, I am able to run the test file and trying to make sense of the results.

Kind regards,
Jan 5 at 3:53 PM
netDxf will help you reading dxf files into something more meaningful, you could even load a dxf as a single string, but that is not be very useful, isn't it?. After that is up to you what you do with the content of the DxfDocument, you will have to make the translation into whatever the G code requires.

I am not familiar with G code, but if it is in any way similar to HPGL, a cutting machine is basically a plotter that has a cutting head instead of a pen, in this case a file would be generated that the plotter will understand, but this conversion is your responsibility.

Jan 6 at 9:25 AM
Hi Daniel,

Thanks for your reply. Though there are many application out there doing the conversion from dxf to g codes for cnc machines, I couldn't find any C# library. I will look into it in more details and see what I can come up with.

In the mean time, I can use this library to find the coordinates and send them directly to the controller. The g code conversion was an optional thing I needed later for 3D printing applications.

Thanks for this library though :)

Kind regards,
Jan 27 at 3:25 PM

I was busy using your library for while. I went through the documentation about the ability to identify shapes such as rectangle or triangle from a combination of lines or polylines. I believe there is no such functionality yet to group entities to certain shapes. I wanted to know if I was missing something.

Kind regards,
Jan 30 at 6:10 PM
No, there is no functionality for such things. It is much better to restrict to the use of LwPolylines, in case you do not have any control over the way the drawings are made you will have to do it manually, a brute force search is simple but slow process.

Feb 22 at 8:54 PM
I am using this library for more or less the same thing. but currently i'm using Bobcad21 to generate the gcode.and this library to read the g code to dxf for visualization in autocad. im using Bobcad21's gcode files to generate/scale/rotate project onto a Cavity in c# then get a dxf visualization
Mar 17 at 2:33 PM
@Darkpoenix, Hello! How are you changing the g code to DXF file? Are you parsing the data?

@Daniel Hi. Is there a way to know what type of entities are connected to, lets say a line entity? When I get the coordinates of a line, I wanted to know whether there is an entity connected to either end of the line and what type is it. That way, I can understand that I can move via that entity and do the same check when I am at the other end of it.
Mar 18 at 5:40 PM
@ataur916 The only way is to make the test it yourself, you will have to check the coordinates of their ends to decide if two entities are connected or not. The dxf does not hold any information about this.

Mar 20 at 9:57 AM
Thanks Daniel. I can manage that.