Skip to main content

CNC G and M Code code parseer

Project description

NCParse (Formally GCodeParser)

Python library to parse GCode into its components

About

GCode Parser was originally packed into my newest project CNClingish. However, I thought it would be just as useful by itself.

Install

Install via pip

python3 -m pip install NCParse

pip Page

Code Sample

file = '../test.nc'

dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, file)
with open(filename, 'r') as f:
    for line in f:
        line = line.strip()
        if not line.startswith('(') and not line.startswith('%') and len(line) > 0:
            print('> ' + line)
           GCode.parse_line(line)

The above code will take a .nc file, look at each line, and run it through parse_line method of the GCode class and split it into its components.

Sample Ouput

the non-indented lines are the original line of code passed into the parser. The indented code are each of the parsed commands with their letter, number, and coordinates (if provided)

> T1 M06 (Select tool 1) ;
        T 1
        M 06
> G00 G90 G40 G49 G54 (Safe startup) ;
        G 00
        G 90
        G 40
        G 49
        G 54
> G00 X0 Y0 (Rapid to 1st position) ;
        G 00 (0, 0, 0)
> S1000 M03 (Spindle on CW) ;
        S 1000
        M 03
> G43 H01 Z0.1 (Tool offset 1 on) ;
        G 43
        H 01 (0, 0, 0.1)
> M08 (Coolant on) ;
        M 08
> G12 I0.75 F10. Z-1.2 D01 (Finish pocket CW) ;
        G 12
        I 0.75
        F 10. (0, 0, -1.2)
        D 01
> G00 Z0.1 (Retract) ;
        G 00 (0, 0, 0.1)
> G00 Z0.1 M09 (Rapid retract, Coolant off) ;
        G 00 (0, 0, 0.1)
        M 09
> G53 G49 Z0 M05 (Z home, Spindle off) ;
        G 53
        G 49 (0, 0, 0)
        M 05
> G53 Y0 (Y home) ;
        G 53 (0, 0, 0)
> M30 (End program) ;
        M 30

TODO

  • Implement parsing for if statements used by some machines (HAAS)
  • Clean-up

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

NCParse-1.0.7.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

NCParse-1.0.7-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file NCParse-1.0.7.tar.gz.

File metadata

  • Download URL: NCParse-1.0.7.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

File hashes

Hashes for NCParse-1.0.7.tar.gz
Algorithm Hash digest
SHA256 d82c35a8bee59a275eb4f596a17c85829073adeadfdbf0de85ea91a8fba15f1f
MD5 20002eafa23bd0ff4a1435ced18d2b68
BLAKE2b-256 4cad6ebf443a9e77f8ff41a1bb217669e26d503d57492b6e9ce0088aff8e7ac6

See more details on using hashes here.

File details

Details for the file NCParse-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: NCParse-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

File hashes

Hashes for NCParse-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6f729764b0690d5709f37e06ddcb8943974053cd671e80601350f1b560437a36
MD5 9a3bc29d4e912433a305dc715fb16541
BLAKE2b-256 a339ec72ea5f0a5c02795cb5d46919baf0eb7431fbefcf96aa6f322a9d76083a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page