a cura post processing script for evaluating arithmetic and logical expressions in g-code
Report Bug
·
Request Feature
This post-processing script allows you to perform math and logic operations in the start and end G-Code. Unlike Slic3r, Cura doesn't support this feature out of the box. With this script, you can evaluate arithmetic and logical expressions, giving you more control over your G-Code and making your workflow smoother.
Cura version 3.1.0 or newer
- In Cura go to
Help > Show Configuraiton Folder
- In the Configuration Folder open the
scipts
folder and paste the ArithmLogicExprEval.py script - Restart Cura
- Click on the Post-Processing button
</>
next to theSlice
Button. - Click
Add a script
- Choose
Arithmetic and Logical Expression Evaluation
Expressions can be defined in start- and end- G-code as well as in other post-processing scripts. When defining expressions in post processing scripts make sure those scripts are executed before this script.
Expressions must be in Python syntax. You can use any arithmetic and logical operators as well as parentheses and decimal points.
For example this start G-code draws a puge line at the Initial Layer Speed. {speed_layer_0}
returns the Initial Layer Speed in mm/s. Therefore the expression gives the Initial Layer Speed in mm/min
G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.3 F{speed_layer_0}*60 E15 ; Draw the first line
G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little
G1 X0.4 Y20 Z0.3 F{speed_layer_0}*60 E30 ; Draw the second line
By default expressions in comments are ignored. You can tick the Evaluate Comments
checkbox to evaluate expresions in comments.
The result of boolean expressions is represented as binary as this is the typical boolean representation in gcode. You can change the Boolean Representation
to text in the options.
This doesn't affect the boolean representaion in the expressions. Remeber that python uses text boolean representation (True
False
).
Distributed under the GNU LGPL v2.1 License. See LICENSE for more information.