Skip to content

Commit

Permalink
Big update
Browse files Browse the repository at this point in the history
Fixed a couple of bugs

Added documentation and available models list
  • Loading branch information
egeakman committed Apr 8, 2022
1 parent 5585acc commit 40db1e3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 30 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ __pycache__/
*.egg-info/
dist/
build/
README_new.md
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ copy of the Program in return for a fee.


gcode2zaxe <https://github/egeakman/gcode2zaxe>
Copyright (C) 2022 Ege Akman <[email protected]>
Copyright (C) 2022 Ege Akman <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
Expand Down
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
Docs coming soon!
# gcode2zaxe

A CLI application that converts gcode files to Zaxe print-ready files. You can use it from the command line after installing it. The executable name is `g2z`. **Don't forget to star the project on [GitHub](https://github.com/egeakman/gcode2zaxe).**

## Installation

Run:&nbsp; ``python -m pip install --upgrade gcode2zaxe``

## Usage

* Show help: ``g2z -h``

* Convert gcode file to zaxe file: ``g2z -g <gcode_file_path>``

## Optional Parameters

* ``-n, --name:`` Output file base name. Defaults to the gcode file name -> (``-g <gcode_file_path>``).

* ``-f, --filament:`` Filament type. Defaults to ``zaxe_pla``. Materials mostly start with ``zaxe_``.

* ``-d, --nozzle_diameter:`` Nozzle diameter. Defaults to ``0.4``.

* ``-m, --model:`` Zaxe printer model. Defaults to ``X1``. See available models in the [models list](https://github.com/egeakman/gcode2zaxe/blob/master/resources/models.json).

## Contributing

* If you have any suggestions or found any bugs, please open an issue or create a pull request.

* Don't hesitate to open an issue if you have any questions about the code.

## Footnotes

* This application does not guarantee that the output file will be valid or compatible with the printer.

* Use at your own risk. I take no responsibility for any damage to your printer.

* This application has no affiliation with Zaxe or its affiliates.

* This project is licensed under the [AGPLv3 license](https://raw.githubusercontent.com/egeakman/gcode2zaxe/master/LICENSE).
53 changes: 29 additions & 24 deletions gcode2zaxe/convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import os
import json
import zipfile
Expand All @@ -11,10 +12,7 @@
parser = ArgumentParser()
parser.add_argument("-g", "--gcode", help="gcode file to convert", required=True)
parser.add_argument(
"-n", "--name", help="name of the model", required=False, default=None
)
parser.add_argument(
"-o", "--output", help="output folder", required=False, default=os.getcwd()
"-n", "--name", help="name of the output file", required=False, default=None
)
parser.add_argument(
"-f",
Expand All @@ -33,20 +31,18 @@

snapshot = os.path.join(TMP, "snapshot.png")
infopath = os.path.join(TMP, "info.json")

if args.name is None:
args.name = args.gcode

if args.output is os.getcwd():
zaxepath = f"./{args.name}.zaxe"

else:
zaxepath = f"{args.output}/{args.name}.zaxe"
tmp_gcode = os.path.join(TMP, "o.gcode")
args.name = (
args.gcode
if args.name is None
else os.path.join(os.path.dirname(args.gcode), args.name)
)
zaxepath = f"{args.name}.zaxe"


def create_zaxe():
with zipfile.ZipFile(zaxepath, "w", zipfile.ZIP_DEFLATED) as f:
f.write(os.path.join(TMP, "o.gcode"), "data.zaxe_code")
f.write(tmp_gcode, "data.zaxe_code")
f.write(snapshot, "snapshot.png")
f.write(infopath, "info.json")

Expand All @@ -58,7 +54,7 @@ def convert_to_bytes(value):

def md5():
hash_md5 = hashlib.md5()
with open(os.path.join(TMP, "o.gcode"), "rb") as f:
with open(tmp_gcode, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
Expand Down Expand Up @@ -87,27 +83,36 @@ def make_info():
return {
"material": args.filament,
"nozzle_diameter": args.nozzle_diameter,
"filament_used": read_gcode()["filament_used"],
"filament_used": read_gcode()["filament_used"]
if "filament_used" in read_gcode()
else 0,
"model": args.model,
"checksum": md5(),
"name": args.name,
"duration": read_gcode()["time"],
"extruder_temperature": 220,
"bed_temperature": 60,
"name": args.name.split("/")[-1]
if args.name.split("/")[-1] != args.name
else args.name.split("\\")[-1],
"duration": read_gcode()["time"] if "time" in read_gcode() else "00:00:00",
"version": "2.0.0",
}


def cleanup():
with contextlib.suppress(FileNotFoundError):
os.remove(tmp_gcode)
os.remove(infopath)
os.remove(snapshot)


def main():

encoded = convert_to_bytes(args.gcode)

with open(os.path.join(TMP, "o.gcode"), "wb") as f:
with open(tmp_gcode, "wb") as f:
f.write(encoded)

with open(os.path.join(TMP, "info.json"), "w") as f:
with open(infopath, "w") as f:
f.write(json.dumps(make_info()))

open(os.path.join(TMP, "snapshot.png"), "w").close()

open(snapshot, "w").close()
create_zaxe()
cleanup()
12 changes: 12 additions & 0 deletions resources/models.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"models": {
"Zaxe X1": "X1",
"Zaxe X1+": "X1_plus",
"Zaxe X2": "X2",
"Zaxe X3": "X3",
"Zaxe XLite": "X_lite",
"Zaxe Z1": "Z1",
"Zaxe Z1+": "Z1_plus",
"Zaxe Z3": "Z3"
}
}
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def latest_version(package_name):
description="Gcode to Zaxe Converter | executable: g2z",
long_description=long_description,
long_description_content_type="text/markdown",
version="2022.4.7",
version="2022.4.8",
license="AGPLv3",
download_url="https://github.com/egeakman/gcode2zaxe/archive/2022.4.7.tar.gz",
packages=find_packages(where=".", exclude=["tests"]),
download_url="https://github.com/egeakman/gcode2zaxe/archive/2022.4.8.tar.gz",
packages=find_packages(where=".", exclude=["tests", "resources"]),
python_requires=">=3.5",
entry_points={
"console_scripts": [
Expand Down

0 comments on commit 40db1e3

Please sign in to comment.