Creating gcode

hello, I am very new in creating gcode for 3d-printing. I have a geometry and I want to make it with 3d-printer but I don’t know how can I create Gcode for it, I would be appreciated if anyone can help me.
spiral tower.gh (14.0 KB)

Particular reason you don’t just bake the geometry and use a slicer (Cura etc.)?

you mean I only need to bake the geometry and use Cura software to print it? if I want to create gcode in grasshopper is it possible?

well, you can for sure extrapolate data from a geometry, and use those as bricks to create gcode

for instance (this is taken from Marlin) a G1 command accepts the following parameters

Linear Move | Marlin Firmware

from your drawing you can get an ordered list of vertexes, and use those to start the creation of G1 linear movements like this:

depending on what you are doing, E might be a function of the length of the segment you just moved along, and you can continue composing your commands as text by concatenating (or Text Join)

spiral tower_inno.gh (17.9 KB)

3 Likes

It depends on what your objective is. If you want to print things you’ve designed in GH then do what Ftzuk said - finish your design, bake it to an STL file, and send that to a slicer program.

But if you want to learn more about GH and how to write scripts and Python/C code, try making your own Gcode.

Note that it is fairly easy to write nice looking Gcode, but it is far more difficult to write Gcode that actually works.

1 Like

thank you for your great help, can I use this code to print my model after I convert it into txt file?
also I have a question about the linear movement in this code, the starting point for print is 0 and also this is the point that printer goes to next surface?

did you have a look at this?

looks promising

I have no idea what material you are printing and what kind/size of machine you are using, but before diving into gcode creation and similar in GH I would first build a solid blackbone and understanding of all the key principles and methods involved

I guess relying on external slicers like Cura, as suggested, would be the best approach

Ask yourself why you want to create g-code by hand? I understand that some people enjoy the process and find it interesting, but for me my time is limited and I’d rather spend time working on designs and let slicers handle the g-code for the 3d printer.

In the end grasshopper is a process of creating geometry. Geometry can be baked & exported as an STL file for the slicer to handle.