*as per 3D-Printing needs
This library is under development - method names, workflow and logic will differ between releases!
Ensure your printer software can catch illegal g-code moves, as this library has still very large amount of bugs! Also keep an eye on your print.
Feature | Status | command |
---|---|---|
Translate Gcode | ✅ | GcodeTools.translate(gcode, Vector) |
Rotate Gcode | ✅ | GcodeTools.rotate(gcode, int) |
Scale Gcode | ✅ | GcodeTools.scale(gcode, Vector|float) |
subdivide Gcode | ✅ | move.subdivide(prev, step) |
Get move's flowrate | ✅ | move.get_flowrate(prev) |
Set flowrate (in mm^2, use scale to set in %) |
✅ | move.set_flowrate(prev, float) |
Detect Gcode features | ✅ | GcodeTools.fill_meta(gcode) |
Split layers | 🔜 | gcode.get_by_meta(str, Any) |
Split bodies | 🔜 | GcodeTools.split(gcode) |
Insert custom Gcode | ❌ | |
Read Thumbnails | ✅ | GcodeTools.get_thumbnails(gcode) |
Generate Thumbnails | ✅ | GcodeTools.generate_thumbnail(gcode, data, width, height, textwidth) |
Convert from/to Arc Moves | ❌ | |
Find body bounds | ✅ | GcodeTools.get_bounding_cube(gcode) |
Trim unused Gcode | 🔜 | GcodeTools.trim(gcode) |
Offset Gcodes in time | ❌ | |
Create custom travel movement | ❌ | |
convert to firmware retraction | 🔜 | GcodeTools.regenerate_travels(gcode) |
- ✅ Fully supported
- ❌ Not yet supported, to be implemented
- 🔜 Partially supported, to be implemented
More features soon! Feel free to open feature request
Gcode (list[Block])
│
├─ slicing config: Config
│
├─ single Gcode instruction: Block
│ │
│ ├─ Object handling everything move-related: Move
│ │ ├─ Position: Vector
│ │ └─ speed: float
│ │
│ ├─ Everything G-code related other than position: BlockData
│ └─ Slicer-specific features (meta): dict
└─ ...
In each block, every G-Code variable is contained. That means, blocks can be taken out of Gcode, rearranged, etc.
That however does not take move origin (move starting position) in count! regenerate_travels
will be able to handle that in future.
from gcode import Gcode
gcode = Gcode()
gcode.from_file('file.gcode')
my_tqdm = tqdm(unit="lines", desc="Reading Gcode")
update = lambda i, length: (setattr(my_tqdm, 'total', length), my_tqdm.update(1))
gcode = Gcode().from_file('file.gcode', update)
Example to move objects that have benchy
in their name, by translation
vector.
from gcode_tools import Gcode, GcodeTools, Vector
do_verbose = False
gcode = Gcode()
gcode.config.speed = 1200 # initial speed before first Gcode's `F` parameter
gcode.from_file('file.gcode')
meta_gcode: Gcode = GcodeTools.fill_meta(gcode)
out_gcode = GcodeTools.trim(meta_gcode)
translation = Vector(-200, -100, 0)
for x in out_gcode:
obj: str = x.meta.get('object')
if 'benchy' in obj.lower():
x.translate(translation)
out_gcode = GcodeTools.regenerate_travels(out_gcode)
out_gcode.write_file('out.gcode', do_verbose)
Tested with:
- Prusa Slicer
2.8.1
- Orca Slicer
2.1.1
- Super Slicer
2.5.59.12
- Slic3r
1.3.0
- Cura
5.8.1
- Simplify3D
4.0.0
Any slicer | Cura | Prusa Slicer | Orca Slicer | Slic3r | Super Slicer | Simplify3D | |
---|---|---|---|---|---|---|---|
Reading Gcode | ✅ | ||||||
Keep track of coordinates | ✅ | ||||||
Temperature control | ✅ | ||||||
Fan control | ✅ | ||||||
Spliting Objects | ❌ | ✅ | ✅1 | ✅ | ❌ | ✅ | ✅ |
Extracting features | ❌ | ➖ | ✅ | ✅ | ❌ | 🔜 | ✅ |
Arc Moves | 🔜2 |
1: Turn on LABEL_OBJECTS
2: Arc moves currently automatically translate to G1 moves
- ✅ Fully supported
- ❌ Not supported, limited by slicer
- 🔜 To be implemented
- ➖ Partially supported, limited by slicer