Skip to content

Instantly share code, notes, and snippets.

@frankbags
Last active January 21, 2023 08:38
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
@frankbags
Copy link
Author

Those are placeholder values from Cura, they will be replaced by the first layer temp for both the hotend and the bed. If this doesn't work then something is wrong with your Cura. I don't know if Philbaz's screenshot will help you because I don't believe I have the plugin for printer settings and I never ran into issues.

thanks for this nice plugin. maybe you can extend it, with a checkbox for following option:

please translate the START_PRINT BED_TEMP={material_bed_temperature_layer_0} EXTRUDER_TEMP={material_print_temperature_layer_0} to the real temperature. i dont know why, but {material_bed_temperature_layer_0} and {material_print_temperature_layer_0} are not translated in the output g-code. that suxx. my klipper does not work propperly, without a number, like BED_TEMP=100. in klipper i import the varables, with attched sequence. everything works fine when is set BED_TEMP=100, but this {material_bed_temperature_layer_0} does not work.

@ORGATHM
Copy link

ORGATHM commented May 3, 2022

okay, that sounds promising. normaly i thought that {material_bed_temperature_layer_0} contains data. but in my spezial case, it would not be translated into the gcode. i think its a good possibility for me, to install cura 5.0 and check if this work better.

@ORGATHM
Copy link

ORGATHM commented May 3, 2022

@frankbags you are right. its unbeleavable. it was cura`s fault. with fresh installed cura (5.0.0 + 4.13.1) and deleted profile folder, it works with the variables. i think its better when i delete some desinformation in my post. now it works as it should. thank you for your help, and sorry for bothering you.

@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