Code structure, best way

I’m kidding a bit with cnc and gcode, but I think I need a more accurate direction of how to structure my code for generate gcode with c# plugin.

Can anyone point me in a direction? Best way to make my code?


What do you have?

Hello @rgr , sorry delay, I’ve been away for a while.

I basically have very little things:

I understand the whole coordinate system
I understand the whole concept Gcode G0 / G1 coordinate ect.
I also know how to take curves and generate a simple gcode based on some parameters

But I need to structure the code correctly, ex:

How to structure to create multiple toolpaths in the same drawing, and to be able to modify or change separately

How to structure so, the same job generate gcode for various “postprocessor” cnc controllers,

I have an idea that the whole toolpath should be created the same way, the only different thing is the postprocessor.


Ok so the problem here is that you have still a lot of variables to work with. I would suggest to answer yourself questions such as:

What strategies are you using? 2D? 2.5D? 3D? All?
What will the basic workflow be like? Be as basic as possible. Leave sophisticated editing methods for once you have a running base you can work on.
Concentrate on delivering a simple G-Code based on RS 274 (or the machine you have available currently) from a basic input such as a set of points.

Once you have working methods for, say, a simple 2D toolpath, you can create multiple 2D paths on different levels and connect them for a 2.5D path. This would be the first thing I would start, create a method that delivers you a consistent 2D result, then translate it according to your strategy.

Starting from a base G-Code, you could either write translate methods for each postprocessor and choose accordingly.