Python gcode parser
Project description
GcodeParser
A simple gcode parser that takes a string of text and returns a list where each gcode command is seperated into a python object.
The structure of the python object is:
G1 X10 Y-2.5 ; this is a comment
GcodeLine(
command = ('G', 1),
params = {'X': 10, 'Y': -2.5},
comment = 'this is a comment',
)
Install
pip install gcodeparser
Alternatively:
pip install -e "git+https://github.com/AndyEveritt/GcodeParser.git@master#egg=gcodeparser"
Usage
from gcodeparser import GcodeParser
# open gcode file and store contents as variable
with open('my_gcode.gcode', 'r') as f:
gcode = f.read()
GcodeParser(gcode).lines # get parsed gcode lines
Include Comments
GcodeParser
takes a second argument called include_comments
which defaults to False
. If this is set to True
then any line from the gcode file which only contains a comment will also be included in the output.
gcode = (
'G1 X1 ; this comment is always included\n',
'; this comment will only be included if `include_comments=True`',
)
GcodeParser(gcode, include_comments=True).lines
If include_comments
is True
then the comment line will be in the form of:
GcodeLine(
command = (';', None),
params = {},
comment = 'this comment will only be included if `include_comments=True`',
)
Converting to DataFrames
If for whatever reason you want to convert your list of GcodeLine
objects into a pandas dataframe, simply use pd.DataFrame(GcodeParser(gcode).lines)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for gcodeparser-0.0.2b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 727d7f58f6aa0dcfc027befe17daf386eed5fbf7d5262f4339aa94ad27d4ee30 |
|
MD5 | 9a8ed0d701eed5c76b8d6116174b4e56 |
|
BLAKE2b-256 | 8b53af26ff7ef572c06abf93a472472284c0fdbf6955dd526d3104a6acbf9512 |