PlanetCNC TNG and Python relation

Python is a programming language known for its simplicity and large standard library. PlanetCNC TNG can use Python to extend its functionality. In most cases as a custom G-code generators, external data processing or control.

If we want to equip TNG with Python functionality, we need to install the Python interpreter to our computer. We recommend that installed version is embeddable Python since this makes it a dedicated interpreter only for needs of TNG.

Of course you can choose also system version of Python interpreter. Either way, be attentive to 32-bit or 64-bit version that you intend to use, depending on your OS.

How does it work?

TNG issues a request to Python interpreter for a script execution. Python script code uses dedicated PlanetCNC Python commands, and that is basically how the Python interpreter communicates with the TNG. These commands are implemented in two TNG Python modules named: 'gcode' and 'planetcnc'.

Python scripts can be directly executed, they can be imported or you can run them via Expr and/or G-code commands.

Not all scripts can be imported, this is conditioned by types of commands used in the script code.

Available documentation

TNG User Manual → Python related program features related settings

G-code ref manual → Python expression functions, Python modules and dedicated commands

Samples folder (located at installation directory in PlanetCNC/Samples folder).

Recommended examples:

NOTE: Do not confuse TNG’s internal embedded python interpreter with TNG Python API.

API’s main purpose is to control TNG from external app, while TNG internal embedded Python interpreter is to run Python scripts within the TNG.