Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@LordFlashmeow
Copy link

On MacOS with Cura 5.0, the path to the scripts folder is /Applications/Ultimaker-Cura.app/Contents/MacOS/share/cura/plugins/PostProcessingPlugin/scripts/

(You may need to right-click on the Cura app and click "Show Package Contents" if you're navigating with Finder)

@damiandudycz
Copy link

Doesn't work for my using Cure 5.1. Anyone else tested with this version?

@frankbags
Copy link
Author

I just tested it with 5.1 after using it with 5.0 since its release and there are no issues on my end.

@esc247
Copy link

esc247 commented Aug 5, 2022

Hi, I just used it with Cura 5.1 on a mac as well. No issues. Thanks for this!

@esc247
Copy link

esc247 commented Sep 7, 2022

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

@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.

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