Skip to content

Added support for gcode generated in Prusa and Orca slicer #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
18b5874
adapted script to prusa slicer
WatchingWatches Mar 21, 2024
4e846bd
added README.md
WatchingWatches Mar 21, 2024
273aa73
added pictures for README
WatchingWatches Mar 21, 2024
ac86e95
added unstable Orca version
WatchingWatches Mar 22, 2024
d4bee80
added pictures to README
WatchingWatches Mar 22, 2024
59eba2c
Delete cura_script_test.gcode
WatchingWatches Mar 22, 2024
876057a
Delete cura_test_gradientinfill.gcode
WatchingWatches Mar 22, 2024
4000741
Delete Orca/orca_script_result.gcode
WatchingWatches Mar 22, 2024
dbf91b3
Delete Orca/test_test.gcode
WatchingWatches Mar 22, 2024
09bb9ec
Delete Prusa/new_prusa_test.gcode
WatchingWatches Mar 22, 2024
75e4d4c
Delete Prusa/prusa_script_result.gcode
WatchingWatches Mar 22, 2024
c4cd599
Delete Prusa/test_gradientinfill.gcode
WatchingWatches Mar 22, 2024
aab2d18
Delete Prusa/orca_test.gcode
WatchingWatches Mar 22, 2024
cf83490
added comments
WatchingWatches Mar 25, 2024
fa9c82b
Merge branch 'master' of https://github.com/WatchingWatches/GradientI…
WatchingWatches Mar 25, 2024
54143a9
addition to slicer settings guide
WatchingWatches Apr 11, 2024
2b51469
added run in orca slicer feature
WatchingWatches Apr 18, 2024
d5cf973
added guide
WatchingWatches Apr 18, 2024
5c468d3
updated Readme
WatchingWatches Apr 18, 2024
0d068b8
added gcode preview example
WatchingWatches Apr 18, 2024
ae9c79b
one output when executed in slicer
WatchingWatches Apr 19, 2024
d4dfb60
updated README
WatchingWatches Apr 19, 2024
f27f77b
added information
WatchingWatches Apr 20, 2024
64ff9f0
revert file
WatchingWatches Apr 22, 2024
8699ca1
added advice
WatchingWatches Apr 22, 2024
47a67b2
Update README.md
WatchingWatches Apr 22, 2024
091a3b6
Update README.md
WatchingWatches Apr 22, 2024
80d0f51
Update README.md
WatchingWatches Apr 22, 2024
c7a756e
added slicer setting requirement
WatchingWatches May 9, 2024
290a67b
fixed issue with supports
WatchingWatches May 10, 2024
a9451fc
implemented maximum volumetric flow
WatchingWatches May 20, 2024
ade3dcc
fixed issue with start gcode
WatchingWatches Jul 3, 2024
154412f
fixed issue with start gcode
WatchingWatches Jul 4, 2024
8943309
fixed issue with verbose gcode in combination with thin core
WatchingWatches Jul 4, 2024
8e4755c
added predefined ignore_pos bool
WatchingWatches Jul 5, 2024
bf95cf5
Readme changes
WatchingWatches Sep 18, 2024
631b017
Readme changes
WatchingWatches Sep 18, 2024
1ccf02e
compatibel with multiple slicers added bambu and cura
WatchingWatches Sep 22, 2024
03af6c5
automatic slicer recognition
WatchingWatches Sep 23, 2024
e185be1
restructured files
WatchingWatches Sep 24, 2024
cbe4014
merged with limit_volumetricflow
WatchingWatches Sep 24, 2024
bbe5784
updated Readme
WatchingWatches Sep 24, 2024
f6a3770
hotfix for linear volumteric flow limit
WatchingWatches Sep 30, 2024
9c7e57b
error for G2/3 command and find volumetric flow from gcode
WatchingWatches Apr 16, 2025
1a40091
automatically find if run in slicer and some clean up
WatchingWatches Apr 17, 2025
79c11b2
fixed bug in volumetric flow, added near wall/collinear detection
WatchingWatches May 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Watch my YouTube video about it: https://youtu.be/hq53gsYREHU

# Important Notes

In its current for it only works with G-Code files generated with CURA due to the comments CURA puts into the G-Code files.
In its current for it only works with G-Code files generated with CURA, Prusa, Bambu and Orca Slicer due to the comments the slicer puts into the G-Code files.
In the "Universal" folder is the script compatible with all of the mentioned slicers and detailed instructions.

It is also important to make sure that the "Walls" are printed before the "Infill" ("Infill before Walls" OFF).
For this script to work, also activate "Relative Extrusion" under "Special Modes".
Expand Down Expand Up @@ -39,3 +40,6 @@ Add a gradual speed variation for machine without direct drive extruder.

Sample part with a Gradient distance set to 8 mm :
![82570108_1223017127904648_3642722292435255296_o](https://user-images.githubusercontent.com/11015345/72863337-8e827580-3cd0-11ea-9681-e1de7e2071c2.jpg)

# GradientInfill by WatchingWatches
Adapted version of the script addGradientInfill.py, which works with Prusa, Bambu, Cura and Orca slicer. The universal_addGradientinfill.py script automatically recognizes the slicer. The script has a own folder: Universal, with a Readme. Also Check the different branches for beta releases with new features.
110 changes: 110 additions & 0 deletions Universal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Gradientinfill for Orca, Bambu, Prusa and Cura slicer:

If you are running the script from the slicer there will be just one output file. I recommend testing the script first inside of an IDE and compare the original and modified file.

The following part was originally written as a guide for prusa slicer, but the slicer settings are the same, but might be found at a different location with a slightly different name.

## Introduction what changed?:

This is a fork of the repository of CNC-Kitchen. I didn't change the working principal of the script. I mainly adapted the comments within the gcode file to suit those generated by Orca, Bambu and Prusa slicer and changed a few things which resulted in errors previously (used re patterns instead of searching for single characters in line).
I implemented an volumetric flow limit and other minor improvements. The script can recognize, which slicer generated the gcode and works with Orca, Bambu, Prusa and Cura slicer. There is also a option to reduce the line width in the core with `THIN_INNER_CORE: bool = True`.
To understand better how the script works, I recommend watching the YouTube video and reading the README.md in the main folder. There you can also find instructions to install python (I'm using python 3.9.18 with the anaconda distribution).

### Example:

In the pictures you can see the change in line width, which was the original function. When you increase the line width, but don't change the print speed you will increase the volumetric flow, which can be too much for your hotend. I implemented a flow limit, which decreases the printing speed when the flow is getting too much (18 mm^3/s in the example). The maximum velocity is set by the initial velocity.

![different line width](pictures/Width.png)
![different flow](pictures/Flow.png)
![different speed](pictures/Speed.png)

Here you can see it applied in a real print:
<img src="pictures/example_print.jpg" alt="first example" width="70%">

### Unclean extrusion:

Often times Infill generates lines, which look like perimeters. The problem is, that there is no space for the line to expand to, like in the core of the Infill.
This results in unclean extrusions, which have an increased height, which results in marks on the top layers. To fix this, lines which are nearly collinear to the perimeter (small angle) don't get modified and stay at their original width.
The feature currently only works with `SMALL_SEGMENTS`.

<p align="center">
<img src="pictures/unclean_extrusion.jpg" alt="example" width="35%">
<img src="pictures/infill_near_wall.png" alt="example_fix" width="55%">
</p>

## Features:

- The script can be called directly after slicing with an optional dialog in the terminal, which will automatically open (`dialog_in_slicer: bool = True`)
- It's also possible to run the script inside of an IDE (it automatically detects, if it's inside of an IDE)
- If the script didn't do any changes it will print a message. This means something went wrong
- If a bug occurs the error message will be written inside of the terminal. When this happens please review, that all of the entered settings are correct. Open an issue here at this repository and share your gcode and/or 3mf file with settings and the error message to get help
- Automatically find relevant settings from gcode (line width, Infill pattern, maximum volumetric flow)
- The script stops if G2/3 moves are detected, which are not supported

## Slicer settings (enable advanced mode):

Without these slicer settings the script will not work.

### Disable Arc fitting in print settings-> advanced:

![arc fitting](<pictures/Screenshot 2024-03-21 231928.png>)

### Use relative extrusion in printer settings-> general:

![Relative extrusion](<pictures/Screenshot 2024-03-21 232256.png>)

### Infill before perimeter need to be turned off printer settings-> infill:

![Infill](pictures/image.png)

### Wipe while retracting must be disabled:

printer settings -> extruder -> retraction

Also ensure, that the filament override is disabled.

### Automatically call script when saving the file:

![run script](pictures/image-2.png)

Insert the path to your python.exe followed by the path to the python script in print settings -> output options.
Not possible with Cura use the script of 5axes instead for slicer integration. If you want to use my new features run the script from an IDE.

## Running script:

The script gets called after the slicing process.
This means, that the preview inside of the slicer doesn't show the changes of the script.

### Investigate the modified gcode (recommended):

The following steps are recommended and should be performed every time, until you trust the script. There might be errors specific to your gcode, which I haven't thought of. Those could potentially damage your printer.

Open the file inside of a gcode viewer (drag the gcode file into a slicer/gcode previewer [Prusa works well]), to take a look at the modified gcode. Select the line width color scheme to see the difference.
Open the two files inside of notepad++ and compare both files with a plugin called "compare". The program will mark all of the changes in between both files. This is the safest check, since the gcode previewer can give a wrong impression (use a small file).

## General advice:

Experiment with the different parameters. For me a `MAX_FLOW = 350` was set too high and 250 worked better.

Print small test pieces to test your settings. The test pieces don't need to be tall, but the infill section needs to be large enough, so you can actually see the difference in line width.
You may need to lower the infill speed, since the flow increases with the use of the script (the volumetric flow limit within the script can makes this step obsolete if it works correctly).
Check in the preview, that it's not exceeding the maximum flow of the hotend. The line width of the infill shouldn't be much higher than the nozzle diameter in the slicer setting.

When you look at the second picture you can see that the flow in the inner core (outside of the `GRADIENT_THICKNESS` range) isn't changed. If you want a thin infill width in the core (where the forces are the lowest) you can enable `THIN_INNER_CORE: bool = True`.

If you modify a big file the computing time can be several minutes long.
I tried adding a progress bar, but it nearly doubled the execution time, so i removed it.

## Personal recommendation:

You can decrease the run time by using a special interpreter called pypy. For large files it decreased the run time by x7 (may differ on your machine). [Here is an installation guide.](https://doc.pypy.org/en/latest/install.html)

## Prospect for the future:

I will try to optimize the calculation time of the script.
With your help i will debug the script for errors, which might occur.
The next step will be adding an automatic infill pattern recognition.

You may also be interested in [my own postprocessing scripts.](https://github.com/WatchingWatches/Post_processing_gcode).

Thank you for you feedback in advance. Also feel free to adapt the script to other slicers too.
Binary file added Universal/pictures/Flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/IMG_20240321_223411411.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/Speed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/Width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/example_print.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/gcode_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/infill_near_wall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Universal/pictures/unclean_extrusion.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading