Print Start Macro

Good evening. Can someone help me to check 2 things before printing? Have nen start macro in which I would like to query whether a mesh has already been made and a car z calibrate has already been done. That it then no longer makes

gcode:
    {% set T_EX = params.EXTRUDER|default(250)|int %}    ; Get Parameter from Slicer (Start_G-Code Filament)
    {% set T_BD = params.BED|default(110)|int %}
    M117 Prepare Printer ...
    #SET_FAN_SPEED FAN=Base SPEED=0.5 ; Fan Speed Elektronik auf 50%
    SET_PRESSURE_ADVANCE ADVANCE=0.070 ; Pressure Advance setzen ABS+ 
    BED_MESH_CLEAR
    M117 Homing all Axes ...
    G28 ; Home all axes
    M117 Heat up the bed and nozzle ...
    M109 S{T_EX} ; Set Extruder Temp & Wait
    M190 S{T_BD} ; Set Hotend Temp & Wait
    M117 Quad Gantry Leveling ...
     {% if printer.quad_gantry_level.applied|lower == 'false' %}
    {action_respond_info("QGL CHECK: QGL ausfuehren")}
    QUAD_GANTRY_LEVEL
    {% else %}
    {action_respond_info("QGL CHECK: QGL bereits ausgefuehrt")}
    {% endif %}
    #QUAD_GANTRY_LEVEL
    CLEAR_PAUSE
    CLEAN_NOZZLE
    G28 ; Home all axes again after Cleaning
    M117 Auto Calibrating Z Offset ...
    CALIBRATE_Z
    M117 Bed Mesh ...  ; BED_MESH_PROFILE LOAD=Mesh_ABS+ ; BED_MESH Profil ABS+ laden
    #BED_MESH_CALIBRATE AREA_START={params.AREA_START|default("0,0")} AREA_END={params.AREA_END|default("0,0")}
    BED_MESH_CALIBRATE ; Or make clean Bed Mesh Calibrate
    BED_MESH_PROFILE LOAD=default
    M117 Start Printing ...```

This is my Start Macro

Hi Zimbo,

I am also working on a more advanced print_start macro.

You can access the current bedmesh state of the printer using the printer.bed_mesh value. It will return a dictionary of values, use that as you wish to confirm or deny the application of a bed_mesh to your current printer state.

Here is an example script:
{% set container_bedmeshProfileName = printer.bed_mesh.profile_name|string %}

{% if container_bedmeshProfileName == “” %}
RESPOND PREFIX="DEBUG: " MSG=“No profile loaded”
{% endif %}

Thank you. Okay, that means that I make a mesh once at the beginning and then it does not make a new mesh for further prints? Where exactly would I have to enter your lines? My mesh that it creates before printing is called default.
Do I have to change my start code further?

Yes, once you have a mesh, you don’t have to mesh again. Although it is recommended you mesh prior to every print, if you want to save time you can just load a previous mesh using the BED_MESH_PROFILE LOAD=default gcode command.

You can test whether a bed mesh is currently loaded using the printer.bed_mesh.profile_name parameter in the code.

So I would say have some logic after your CALIBRATE_Z command to heck if a bed mesh is loaded. Note that if you keep your BED_MESH_CLEAR command in the macro you will remove the loaded profile. As for how to check whether a profile exists, I am working on it and I will have an answer for you soon.

EDIT:
So after working on this today I used the following script to dump all runtime variables created by the klipper service: (common-macros/search_vars.cfg at main · simplisticton/common-macros · GitHub).

You can see from the readout that there is a parameter called printer.bed_mesh.profiles which should return a dictionary containing all possible profiles. This should allow you to confirm whether a profile exists and act accordingly using jinja logic in the gcode section of your print_start macro.

Okay, and how exactly would you integrate it if you were me? Do you have an example for me that I could try out? That would be great if it works just for a multicolor print with several elements when there is already a printed part in a different color on the bed.

I think the quickest method is to just use the in command in a jinja eval to check if your desired value is inside the dictionary returned by the printer.bed_mesh.profiles dictionary return.

So a line like this should eval correctly:

{% if “profile_name_here” in printer.bed_mesh.profiles %}
Gcode stuff you want to run here
{% endif %}

I have not had time recently to work on this but it should work, let me know if it does.

I think the best way to solve your bedmesh routine problem is to check if the bedmesh profile exists in your profiles, the default profile is saved as default so you can just check if that exists and then start the print after loading it up using the BED_MESH_PROFILE LOAD command

Also I would like to point out that KAMP is native in klipper now so you can just use adaptive bed meshing. I would recommend just using that prior to printing.

Okay thanks. I just want to be able to make a multi-material print. So print the first print part. Leave it on the bed and then print the 2nd part directly afterwards in a different color. So that you have, for example, a different colored logo on a print part. So 2 different colors in one layer.

I just want to be able to make a multi-material print. So print the first print part. Leave it on the bed and then print the 2nd part directly afterwards in a different color. So that you have, for example, a different colored logo on a print part. So 2 different colors in one layer.

What does this have to do with the bed mesh? I do this all the time and have never had any need to do anything special with the mesh.

Yeah, I’m with you, multi material prints shouldn’t need modified bed mesh code or rather even modify the print start macro but should rather be layer change or material change macros set by the slicer which prompts a klipper macro if you want things internalized.