Jump to content

"Slicing" the gcode

AirsoftGuy
Go to solution Solved by AirsoftGuy,

I found it! It still needs some workarounds, but I finally got what I need. I drop in the stl, and spits out the cut out for the plotter with the pieces numbered to order the stack. I save it to DXF, open with inkscape, I delete the un necessary stuff out, then it goes for the cutter and done. 

Now i just have to figure out what shape i sould add in order to make it possible to strip down like in the video.

Thank you guys!

Untitled.png

Hello guys!
I would like a program that reads the sliced gcode and converts it into individual SVG files layer-by-layer.
Just to put it into perspective, this is the basis of my inspiration.
https://www.facebook.com/reel/685180230046409

This is a very basic code from chatGPT. As an amaterur in programming it seems like it should do the thing, but i still have blanks which i'm not sure how to fill in.
https://pastebin.com/efyqbz87

Any positive feed back is a welcome!
Thank you!
Link to comment
Share on other sites

Link to post
Share on other sites

First, any gcode to SVG/DXF converter will just take every move from the gcode and turn it into a line. It's not actually an SVG, just an SVG rendering of the gcode moves, so it's not going to scale up well. Probably not a huge issue. Second, this means your gcode probably needs to be a single outer shell, and it may or may not actually result in a closed shape.

 

As for the code:

 

The biggest problem, ChatGPT didn't actually do anything to turn gcode into SVG. It's telling you to get an OpenSCAD script that turns gcode into svg, then it will run that.

 

The layer detection only works if the gcode has layer comments and they start with ";LAYER:". I think that's Cura's format, so make sure you use Cura or a Cura derivative.

 

Not necessarily a problem, but a hassle for you. It doesn't pad the layer names with 0's, so sorting isn't going to play nice.

(e.g.

layer_199.svg

layer_2.svg

layer_20.svg)

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 Fractal Design Meshify C Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to comment
Share on other sites

Link to post
Share on other sites

What's the actual goal? If you want image cuts of a 3D object like in the video starting from gcode seems pointless, you'd want to start from the 3D model itself instead.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

"...so it's not going to scale up well. Probably not a huge issue." That's not problem at all. I converted a sort part from a legit gcode, and it was scalable with the editor, no problem.

"...your gcode probably needs to be a single outer shell...", yes, exaclty it is. One perimeter, no top, or bottom solid layers, no infill, no retraction, no nothing, just the shell.  "...may not actually result in a closed shape."  yes i'm avare of that. The middle piece needs to be one single shape, because the "islands" can't levitate in place. That will depend on the model, but after slicing i can go through the individual layers to see if it's correct for this purpose.
To answer the layer detection, i use prusa slicer and the ";Layer:" call present in that too. The exact format could be different, but that's a simple correction in the script and we're done.
"...It doesn't pad the layer names with 0's" thank you, i didn't realise that. Now as i think of it, if I set the order not by name, but creation date it should be in order i guess..

" you'd want to start from the 3D model itself instead.", yes I do. I want to slice 3D models, not one specific gcode. But if we manage to make a script for one, than that will suit the others too.

Link to comment
Share on other sites

Link to post
Share on other sites

On 5/6/2023 at 11:29 AM, AirsoftGuy said:

" you'd want to start from the 3D model itself instead.", yes I do. I want to slice 3D models, not one specific gcode. But if we manage to make a script for one, than that will suit the others too.

then just slice 3d models. It's easy, all you need to do is this :

1 - take the model base

2 - compute the height

3 - choose your slice thickness

4 - create a larger rectangle solid with that slice thickness at the first layer

5 - run boolean operation of the model and the rectangular solid

6 - Take the lowest faces (can be many) which has the same normal as the base (parallel)

7 - Get the polygons contour lines (typically counter clockwise is contour and clockwise are holes)

8 - move the rectangular solid up by the layer thickness and do the same for layer 2 and so on

 

 

So you should have your model like this :

image.thumb.png.05dd8efb8b796b34571599787a127eb5.png

 

then once the slice is done you will have regions in red like this and you just need to create you infill like in green here

image.thumb.png.1a2b6bcfc713bdd0956d4ba58299214e.png

then if you fancy a 3d cylinder on lines you get something similar to likes of Cura/Prusa

 

image.thumb.png.22553510806499b1cf7574bf27cb4c69.png

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

My layer height is 0,1mm... For a 10mm tall model i would have to do that 100 times. This is why i want a script to make it. It's a repeated process, it should be working somehow...

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, AirsoftGuy said:

My layer height is 0,1mm... For a 10mm tall model i would have to do that 100 times. This is why i want a script to make it. It's a repeated process, it should be working somehow...

that's what my step 8 is. Repeat the process (4-5-6-7-8) for each layer and it gets you something similar to screenshot i showed.

 

Then it's up to you to generate the actual gcode which there is many many variation out there depending on the controller and model of the device in question.

Some support barely no features, others have custom features that only that device can reads. As an example some grbl controller do not accept tool change commands.

 

If you didn't know gcode existed way before 3d printing existed so it's not specific to 3d printers. 3d printer is a drop in the ocean of device using that language.

Link to comment
Share on other sites

Link to post
Share on other sites

OpenSCAD might be able to do that for you.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

I found it! It still needs some workarounds, but I finally got what I need. I drop in the stl, and spits out the cut out for the plotter with the pieces numbered to order the stack. I save it to DXF, open with inkscape, I delete the un necessary stuff out, then it goes for the cutter and done. 

Now i just have to figure out what shape i sould add in order to make it possible to strip down like in the video.

Thank you guys!

Untitled.png

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×