GcodeTools


NameGcodeTools JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummaryPython G-Code Tools library with complete G-Code Reader and Writer
upload_time2025-02-16 20:37:16
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords 3d g-code gcode printing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python G-Code Tools library with complete* G-Code Reader and Writer

\*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.**


# Available G-Code Tools

| 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 <br> (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)`                 |


### Legend:

- ✅ Fully supported
- ❌ Not yet supported, to be implemented
- 🔜 Partially supported, to be implemented

More features soon! Feel free to open feature request


# G-Code

## Current G-Code object relation:
```
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.


# G-Code Parser

```py
from GcodeTools import Gcode

gcode = Gcode()
gcode.from_file('file.gcode')
```

## Progress Callback example implementation

```py
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 usage

Example to move objects that have `benchy` in their name, by `translation` vector.
```py
from GcodeTools 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: 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.move.translate(translation)
out_gcode = GcodeTools.regenerate_travels(out_gcode)

out_gcode.write_file('out.gcode', do_verbose)
```


# Supported Slicers

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&nbsp;Slicer | Orca&nbsp;Slicer | Slic3r | Super&nbsp;Slicer | Simplify3D |
| ------------------------- | :--------: | :--: | :---------------: | :--------------: | :----: | :---------------: | :--------: |
| Reading Gcode             |     ✅     |      |                   |                  |        |                   |            |
| Keep track of coordinates |     ✅     |      |                   |                  |        |                   |            |
| Temperature control       |     ✅     |      |                   |                  |        |                   |            |
| Fan control               |     ✅     |      |                   |                  |        |                   |            |
| Spliting Objects          |     ❌     |  ✅  |       ✅1       |        ✅        |   ❌   |        ✅         |     ✅     |
| Extracting features       |     ❌     |  ➖  |        ✅         |        ✅        |   ❌   |        🔜         |     ✅     |
| Arc Moves                 |   🔜2    |      |                   |                  |        |                   |            |


### Legend:

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
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "GcodeTools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "3d, g-code, gcode, printing",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/16/1a/83771b831703986db05c5a31478f694108df46e3b08df999d5c9706add51/gcodetools-0.0.1.tar.gz",
    "platform": null,
    "description": "# Python G-Code Tools library with complete* G-Code Reader and Writer\n\n\\*as per 3D-Printing needs\n\n\n**This library is under development - method names, workflow and logic will differ between releases!**\n\n**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.**\n\n\n# Available G-Code Tools\n\n| Feature                                              | Status |                                command                                 |\n| ---------------------------------------------------- | :----: | :--------------------------------------------------------------------: |\n| Translate Gcode                                      |   \u2705   |                 `GcodeTools.translate(gcode, Vector)`                  |\n| Rotate Gcode                                         |   \u2705   |                    `GcodeTools.rotate(gcode, int) `                    |\n| Scale Gcode                                          |   \u2705   |                `GcodeTools.scale(gcode, Vector\\|float)`                |\n| subdivide Gcode                                      |   \u2705   |                      `move.subdivide(prev, step)`                      |\n| Get move's flowrate                                  |   \u2705   |                       `move.get_flowrate(prev)`                        |\n| Set flowrate <br> (in mm^2, use `scale` to set in %) |   \u2705   |                    `move.set_flowrate(prev, float)`                    |\n| Detect Gcode features                                |   \u2705   |                     `GcodeTools.fill_meta(gcode)`                      |\n| Split layers                                         |  \ud83d\udd1c   |                     `gcode.get_by_meta(str, Any)`                      |\n| Split bodies                                         |  \ud83d\udd1c   |                       `GcodeTools.split(gcode)`                        |\n| Insert custom Gcode                                  |   \u274c   |                                                                        |\n| Read Thumbnails                                      |   \u2705   |                   `GcodeTools.get_thumbnails(gcode)`                   |\n| Generate Thumbnails                                  |   \u2705   | `GcodeTools.generate_thumbnail(gcode, data, width, height, textwidth)` |\n| Convert from/to Arc Moves                            |   \u274c   |                                                                        |\n| Find body bounds                                     |   \u2705   |                 `GcodeTools.get_bounding_cube(gcode)`                  |\n| Trim unused Gcode                                    |  \ud83d\udd1c   |                        `GcodeTools.trim(gcode)`                        |\n| Offset Gcodes in time                                |   \u274c   |                                                                        |\n| Create custom travel movement                        |   \u274c   |                                                                        |\n| convert to firmware retraction                       |  \ud83d\udd1c   |                 `GcodeTools.regenerate_travels(gcode)`                 |\n\n\n### Legend:\n\n- \u2705 Fully supported\n- \u274c Not yet supported, to be implemented\n- \ud83d\udd1c Partially supported, to be implemented\n\nMore features soon! Feel free to open feature request\n\n\n# G-Code\n\n## Current G-Code object relation:\n```\nGcode (list[Block])\n\u2502\n\u251c\u2500 slicing config: Config\n\u2502\n\u251c\u2500 single Gcode instruction: Block\n\u2502  \u2502\n\u2502  \u251c\u2500 Object handling everything move-related: Move\n\u2502  \u2502  \u251c\u2500 Position: Vector\n\u2502  \u2502  \u2514\u2500 speed: float\n\u2502  \u2502\n\u2502  \u251c\u2500 Everything G-code related other than position: BlockData\n\u2502  \u2514\u2500 Slicer-specific features (meta): dict\n\u2514\u2500 ...\n```\n\nIn each block, every G-Code variable is contained. That means, blocks can be taken out of Gcode, rearranged, etc.\n\nThat however does not take move origin (move starting position) in count! `regenerate_travels` will be able to handle that in future.\n\n\n# G-Code Parser\n\n```py\nfrom GcodeTools import Gcode\n\ngcode = Gcode()\ngcode.from_file('file.gcode')\n```\n\n## Progress Callback example implementation\n\n```py\nmy_tqdm = tqdm(unit=\"lines\", desc=\"Reading Gcode\")\nupdate = lambda i, length: (setattr(my_tqdm, 'total', length), my_tqdm.update(1))\ngcode = Gcode().from_file('file.gcode', update)\n```\n\n\n# Example usage\n\nExample to move objects that have `benchy` in their name, by `translation` vector.\n```py\nfrom GcodeTools import Gcode, GcodeTools, Vector\n\ndo_verbose = False\n\ngcode = Gcode()\ngcode.config.speed = 1200 # initial speed before first Gcode's `F` parameter\n\ngcode.from_file('file.gcode')\nmeta_gcode: Gcode = GcodeTools.fill_meta(gcode)\nout_gcode: Gcode = GcodeTools.trim(meta_gcode)\n\ntranslation = Vector(-200, -100, 0)\n\nfor x in out_gcode:\n    obj: str = x.meta.get('object')\n    if 'benchy' in obj.lower():\n        x.move.translate(translation)\nout_gcode = GcodeTools.regenerate_travels(out_gcode)\n\nout_gcode.write_file('out.gcode', do_verbose)\n```\n\n\n# Supported Slicers\n\nTested with:\n- Prusa Slicer `2.8.1`\n- Orca Slicer `2.1.1`\n- Super Slicer `2.5.59.12`\n- Slic3r `1.3.0`\n- Cura `5.8.1`\n- Simplify3D `4.0.0`\n\n\n|                           | Any slicer | Cura | Prusa&nbsp;Slicer | Orca&nbsp;Slicer | Slic3r | Super&nbsp;Slicer | Simplify3D |\n| ------------------------- | :--------: | :--: | :---------------: | :--------------: | :----: | :---------------: | :--------: |\n| Reading Gcode             |     \u2705     |      |                   |                  |        |                   |            |\n| Keep track of coordinates |     \u2705     |      |                   |                  |        |                   |            |\n| Temperature control       |     \u2705     |      |                   |                  |        |                   |            |\n| Fan control               |     \u2705     |      |                   |                  |        |                   |            |\n| Spliting Objects          |     \u274c     |  \u2705  |       \u27051       |        \u2705        |   \u274c   |        \u2705         |     \u2705     |\n| Extracting features       |     \u274c     |  \u2796  |        \u2705         |        \u2705        |   \u274c   |        \ud83d\udd1c         |     \u2705     |\n| Arc Moves                 |   \ud83d\udd1c2    |      |                   |                  |        |                   |            |\n\n\n### Legend:\n\n1: Turn on `LABEL_OBJECTS`\\\n2: Arc moves currently automatically translate to G1 moves\n\n- \u2705 Fully supported\n- \u274c Not supported, limited by slicer\n- \ud83d\udd1c To be implemented\n- \u2796 Partially supported, limited by slicer",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python G-Code Tools library with complete G-Code Reader and Writer",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/matszwe02/GcodeTools",
        "Issues": "https://github.com/matszwe02/GcodeTools/issues"
    },
    "split_keywords": [
        "3d",
        " g-code",
        " gcode",
        " printing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cc9974ecf85051183f8eb8d58a39385c239f6df1eac9855e48b7f72828e6a2f2",
                "md5": "26539e8fdf09f6dfa70656628953ff18",
                "sha256": "a9341ac6919a467fce453cb4e12131a6adc582f117ac2eee47449aa0d675da7e"
            },
            "downloads": -1,
            "filename": "gcodetools-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "26539e8fdf09f6dfa70656628953ff18",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18326,
            "upload_time": "2025-02-16T20:37:14",
            "upload_time_iso_8601": "2025-02-16T20:37:14.394247Z",
            "url": "https://files.pythonhosted.org/packages/cc/99/74ecf85051183f8eb8d58a39385c239f6df1eac9855e48b7f72828e6a2f2/gcodetools-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "161a83771b831703986db05c5a31478f694108df46e3b08df999d5c9706add51",
                "md5": "d94617c78e01ae5dba09c59c754e405f",
                "sha256": "2b235edd46965a4987c47f651aabe3c81e7a220b8260c42ad6322d9b588916a2"
            },
            "downloads": -1,
            "filename": "gcodetools-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d94617c78e01ae5dba09c59c754e405f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17265,
            "upload_time": "2025-02-16T20:37:16",
            "upload_time_iso_8601": "2025-02-16T20:37:16.783052Z",
            "url": "https://files.pythonhosted.org/packages/16/1a/83771b831703986db05c5a31478f694108df46e3b08df999d5c9706add51/gcodetools-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-16 20:37:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "matszwe02",
    "github_project": "GcodeTools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "gcodetools"
}
        
Elapsed time: 0.79952s