Skip to content

Instantly share code, notes, and snippets.

@frankbags
Last active November 14, 2023 02:19
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save frankbags/c85d37d9faff7bce67b6d18ec4e716ff to your computer and use it in GitHub Desktop.
Save frankbags/c85d37d9faff7bce67b6d18ec4e716ff to your computer and use it in GitHub Desktop.
Cura post processing script to resize bed mesh to print size

BEWARE

I have not tested this outside of comparing the gcode between SuperSlicer and Cura. Values were within 1mm of of each corresponding value.

I don't know python and have no interest in learning it, hopefully someone can clean this up.

CURA START G-CODE

START_PRINT BED_TEMP={material_bed_temperature_layer_0} EXTRUDER_TEMP={material_print_temperature_layer_0} AREA_START_X=%MINX% AREA_START_Y=%MINY% AREA_END_X=%MAXX% AREA_END_Y=%MAXY%

import re #To perform the search and replace.
from ..Script import Script
class MeshPrintSize(Script):
def getSettingDataString(self):
return """{
"name": "Mesh Print Size",
"key": "MeshPrintSize",
"metadata": {},
"version": 2,
"settings":{}
}"""
def execute(self, data):
minMaxXY = {'MINX':0,'MINY':0,'MAXX':0,'MAXY':0}
lineData = ''
for layer_number, layer in enumerate(data):
for k,v in minMaxXY.items():
result = re.search(str(k)+":(\d*\.?\d*)",layer)
if result is not None:
minMaxXY[k] = result.group(1)
areaStartGcode = re.search(".*%(MINX|MAXX|MINY|MAXY)%.*",layer)
if areaStartGcode is not None:
if not lineData:
lineData = layer
for k, v in minMaxXY.items():
pattern3 = re.compile('%' + k + '%')
lineData = re.sub(pattern3, v, lineData)
data[layer_number] = lineData
return data
@rstudner
Copy link

rstudner commented Jan 5, 2023

On my mac, Cura 5.2.1:
/Applications/Ultimaker-Cura.app/Contents/MacOS/share/cura/plugins/PostProcessingPlugin/scripts/

I don't have a plugins folder under "share"

Which is odd since I have, well, plugins and do post processing scripts.

@Turbine1991
Copy link

can this statement be added to the top of the page please?

*(Cura slicer plugin) To make the macro to work in Cura slicer, you need to install the post process plugin by frankbags - In cura menu Help -> Show configuration folder. - Copy the python script from the above link in to scripts folder. - Restart Cura - In cura menu Extensions -> Post processing -> Modify G-Code and select Mesh Print Size

Enabled by default these days.

@Turbine1991
Copy link

On my mac, Cura 5.2.1: /Applications/Ultimaker-Cura.app/Contents/MacOS/share/cura/plugins/PostProcessingPlugin/scripts/

I don't have a plugins folder under "share"

Which is odd since I have, well, plugins and do post processing scripts.

On Linux it comes in a similar app package bundle. I had to extract it, and then insert the script in there. For some reason my scripts are entirely sourced from here.

Though I'm not crazy enough to own a Mac, so I can't test it out.

@dev-zetta
Copy link

It fails the calibration:

21:40
Internal error on command:"BED_MESH_CALIBRATE"
21:40
Internal error on command:"BED_MESH_CALIBRATE_BASE"
21:40
Klipper state: Shutdown
21:40
bed_mesh: faulty region points
21:40
15 | (69.7, 130.0) | (92.7, 135.0)
21:40
14 | (91.0, 130.0) | (114.0, 135.0)
21:40
13 | (112.4, 130.0) | (135.4, 135.0)
21:40
12 | (133.7, 130.0) | (156.7, 135.0)
21:40
11 | (133.7, 110.3) | (156.7, 115.3)
21:40
10 | (112.4, 110.3) | (135.4, 115.3)
21:40
9 | (91.0, 110.3) | (114.0, 115.3)
21:40
8 | (69.7, 110.3) | (92.7, 115.3)
21:40
7 | (69.7, 90.6) | (92.7, 95.6)
21:40
6 | (91.0, 90.6) | (114.0, 95.6)
21:40
5 | (112.4, 90.6) | (135.4, 95.6)
21:40
4 | (133.7, 90.6) | (156.7, 95.6)
21:40
3 | (133.7, 70.8) | (156.7, 75.8)
21:40
2 | (112.4, 70.8) | (135.4, 75.8)
21:40
1 | (91.0, 70.8) | (114.0, 75.8)
21:40
0 | (69.7, 70.8) | (92.7, 75.8)
21:40
bed_mesh: generated points
Index | Tool Adjusted | Probe
21:40
Generating new points...
21:35
File selected

@esc247
Copy link

esc247 commented Apr 2, 2023

I’ve set up KAMP now and that works well without having to use a pluglin 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment