Skip to content

Instantly share code, notes, and snippets.

@frankbags
Last active November 14, 2023 02:19
Show Gist options
  • 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
@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