What is gcoordinator?
gcoordinator is a library used to generate G-code for 3D printers using Python.
The development started with extracting the G-code generation engine from the GUI application G-coordinator [https://github.com/tomohiron907/G-coordinator].
With this library alone, you can perform 3D modeling, preview, G-code generation, and export.
In the upcoming version 3 series of the GUI application, the plan is to fully migrate the internal generation engine to this library.
Installation
You can install it using the following command:
pip install gcoordinator
Since the dependencies include features that require specific versions to function properly, it is strongly recommended to create a virtual environment. Specifically, you will need matplotlib==3.7.1.
What is G-code?
In essence, the G-code used in 3D printing primarily consists of a series of coordinates where the nozzle moves.
It also includes parameters such as extrusion amount and movement speed, but these are automatically set and calculated within the library.
Therefore, when using the library for modeling, the only consideration needed is the three-dimensional coordinate sequence along which the nozzle moves.
Usage
Below is a sample code for creating the simplest cylinder using the library:
import gcoordinator as gc
import numpy as np
full_object = []
for height in range(100):
arg = np.linspace(0, 2*np.pi, 100)
x = 10 * np.cos(arg)
y = 10 * np.sin(arg)
z = np.full_like(x, (height+1) * 0.2)
wall = gc.Path(x, y, z)
full_object.append(wall)
gc.preview(full_object)
gcode = gc.GCode(full_object)
gcode.start_gcode("PATH TO YOUR START G-CODE")
gcode.end_gcode("PATH TO YOUR END G-CODE")
gcode.save('PATH OF YOUR G-CODE FILE TO SAVE')
modeling
for layer in range(100):
iterating through each layer using a for loop, ranging from layer 0 to layer 99.
Next, we set the angle (arg) in a numpy array from 0 to 2π to draw a circle.
Since the number of elements is set to 100, an exact regular 99-gon will be modeled. If the radius is fixed at 10, the x coordinate is calculated as follows:
radius×cos(arg)
The y coordinate is calculated as follows:
radius×sin(arg)
z = np.full_like(x, (height+1) * 0.2)
As for the z coordinate in the height direction, an array with the same number of elements as arg is initialized with a value according to height.
The reason for adding 1 is that even if the height starts from 0, we want the first layer to be printed at a height of 0.2.
wall = Path(x,y,z)
Create a Path from the x, y, and z coordinate sequences calculated above.
full_object.append(wall)
Add the created Path to a list called full_object.
full_object is a list that stores all the Paths to be printed in the order of printing.
Note that the end point of the nth Path and the start point of the n+1th Path are automatically traveled.
preview
gc.preview(full_object)
Displays the modeling result. It automatically detects the frontend in use, so the same code
previews correctly on both the G-coordinator app and the gcoordinator VSCode extension.
gc.gui_export(full_object) is kept as an alias of gc.preview() for backwards compatibility.
G-code generation
gcode = gc.GCode(full_object)
Convert all the Paths stored in full_object to G-code.
gcode.start_gcode("PATH TO YOUR START G-CODE")
gcode.end_gcode("PATH TO YOUR END G-CODE")
Specify the G-code to be written at the beginning and end of the G-code.
gcode.save('PATH OF YOUR G-CODE FILE TO SAVE')
Save the G-code.
gcoordinaとは?
gcoordinatorは,pythonを用いて3Dプリンタ用G-codeを生成するためのライブラリです.
GUIアプリのG-coordinator[https://github.com/tomohiron907/G-coordinator] のG-code生成エンジンの切り出しを発端に開発開始しました.
このライブラリ一つで,3次元の造形,プレビュー,G-codeの生成,書き出しが可能です.
GUIアプリのver3系列では,内部の生成エンジンを完全にこのライブラリに移行する予定です.
インストール
以下のコマンドでインストール可能です.
pip install gcoordinator
依存ライブラリの中に,指定のバージョンでないと動作しない機能が含まれるため,仮想環境を作成することを強くお勧めします.
具体的には,matplotlib==3.7.1が必要です.
G-codeとは
そもそも,3Dプリンタで用いるG-codeとは,その大部分がノズルが移動していく座標列です.
他にも,押し出し量や移動スピードなどのパラメータも含まれますが,これらはライブラリ内で自動的に設定,計算されます.
従って,ライブラリを使用して造形を行う時に,考慮する必要があるのは,ノズルの移動していく3次元の座標列のみです.
使い方
以下に,最もシンプルな円柱を造形するためのサンプルコードを示します.
import gcoordinator as gc
import numpy as np
full_object = []
for height in range(100):
arg = np.linspace(0, 2*np.pi, 100)
x = 10 * np.cos(arg)
y = 10 * np.sin(arg)
z = np.full_like(x, (height+1) * 0.2)
wall = gc.Path(x, y, z)
full_object.append(wall)
gc.preview(full_object)
gcode = gc.GCode(full_object)
gcode.start_gcode("PATH TO YOUR START G-CODE")
gcode.end_gcode("PATH TO YOUR END G-CODE")
gcode.save('PATH OF YOUR G-CODE FILE TO SAVE')
3次元造形
for layer in range(100):
for文で各レイヤーについて繰り返しをしています.0層目から99層目まで繰り返されるイメージです.
次に,円を描くために,角度(arg)をnumpy arrayで0から2πの範囲で設定しています.
要素数は100としているため,正確には,正99角形が造形されます. 半径は10で固定すると,
x座標は,
半径×cos(arg)
y座標は,
半径×sin(arg)
より計算できます.
z = np.full_like(x, (height+1) * 0.2)
高さ方向のz座標に関しては,argと同じ要素数のarrayをheightに応じて値を初期化しています.
1を足しているのは,heightが0から始まっても,第一層目は高さ0.2の場所に印刷して欲しいからです.
wall = Path(x,y,z)
上で計算したx,y,z座標列のPathを作成しています.
full_object.append(wall)
作成したPathをfull_objectというリストに追加しています.
full_objectは,印刷すべき全てのPathを印刷順に格納したリストです.
なお,n番目のPathの終点とn+1番目のPathの始点とは,自動でトラベルするようになっています.
プレビュー
gc.preview(full_object)
造形結果を表示します.使用中のフロントエンドを自動で判別するため,同じコードでG-coordinatorアプリでも,
VSCode拡張機能のgcoordinator-extensionでもプレビューできます.
gc.gui_export(full_object)は後方互換のためgc.preview()のエイリアスとして残されています.
G-codeの生成
gcode = gc.GCode(full_object)
full_objectに格納された全てのPathをG-codeに変換します.
gcode.start_gcode("PATH TO YOUR START G-CODE")
gcode.end_gcode("PATH TO YOUR END G-CODE")
G-codeの先頭と末尾に書き込むG-codeを指定します.
gcode.save('PATH OF YOUR G-CODE FILE TO SAVE')
G-codeを保存します.
Metadata
Release files for gcoordinator 0.0.24
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gcoordinator-0.0.24.tar.gz | 2.9 MB | Without provenance | Details for gcoordinator-0.0.24.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gcoordinator-0.0.24-py3-none-any.whl | Python 3 | none | any | Details for gcoordinator-0.0.24-py3-none-any.whl |
Total release size: 2.9 MB
Release files / gcoordinator-0.0.24.tar.gz
| Download URL | gcoordinator-0.0.24.tar.gz |
|---|---|
| Size | 2.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ffda0c7b007aef9d402eaa36fbcc62a143e7746adf9de189a36bb11cb0f3aa4d
|
|
BLAKE2b-256 checksum How to use checksums |
933f585d0ca580edc97b9155c1373f49f05142b728f70ef896736d3dd93f6ebd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / gcoordinator-0.0.24-py3-none-any.whl
| Download URL | gcoordinator-0.0.24-py3-none-any.whl |
|---|---|
| Size | 29.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd1aa0fc0c8869dcadb39b806ffb1b86f9cc42d1b3d88a49461b072ed122854f
|
|
BLAKE2b-256 checksum How to use checksums |
21f782c7389a73611e154c3710f0bf8e21cb7094e2db8a74f438256a368143f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for gcoordinator 0.0.24
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.