Jump to content
Ultimaker Community of 3D Printing Experts

How can I make startup GCode that depends on the nozzle diameter?


Recommended Posts

Posted (edited) · How can I make startup GCode that depends on the nozzle diameter?

Hi everyone. I've tried looking in the online guides for this but I can't seem to find anything. I'm using Klipper firmware and I want to set the pressure advance based on the nozzle diameter. Is that something I can do in Cura? Basically what I need is a case statement, or if-then-else. The gcode I need to add is:



For a 0.4mm nozzle the value should be 0.153, for a 0.2mm nozzle it's 0.250, etc. The values are determined by printing a calibration tower and they are different for every nozzle size and in some cases per filament. In Prusa Slicer I've done it like this:

{if nozzle_diameter[0] == 0.2} SET_PRESSURE_ADVANCE ADVANCE=0.250
{elsif nozzle_diameter[0] == 0.4} SET_PRESSURE_ADVANCE ADVANCE=0.153

I imagine there must be some similar technique in Cura, Can anyone point me to the right documentation or an example, please?

Edited by NameOfTheDragon
  • Link to post
    Share on other sites

    Posted · How can I make startup GCode that depends on the nozzle diameter?

    Use the Linear Advance Setting plugin (from the Marketplace) to set your linear advance factor in profiles. Then - since you seem to be using Klipper), add this gcode macro to your printer.cfg:

    [gcode_macro m900]
    default_parameter_K: 0


  • Link to post
    Share on other sites

    • 5 months later...
    Posted · How can I make startup GCode that depends on the nozzle diameter?

    Not sure if have this figured out yet but I do something similar except for different extrusion widths when I was running Marlin. Just changed over to Klipper now and figuring out how I can do the same so still looking into an elegant solution but for the moment I use post-processing in Cura to set my K values

    Basically in my start gcode in Cura I have:
    M140 S{material_bed_temperature_layer_0}    ; Start heating the bed to initial layer temp
    G4 S30                    ; wait 30 secs
    M104 S{material_print_temperature_layer_0}    ; start heating the hot end to initial layer temp
    M190 S{material_bed_temperature_layer_0}    ; wait for bed
    M109 S{material_print_temperature_layer_0}    ; wait for hotend

    In Search and Replace with the checkbox for expressions ticked I do the following
    Search: M190 S85.1\t; wait for bed\nM109 S225\t; wait for hotend
    Replace: ;POST-PROCESSED DETAIL PETG 0.2_0.42\nM190 S85.1\t; wait for bed\nM109 S225\t; wait for hotend\nM92 E414.63\t; set new extruder setting for PETG\nM301 P14.19 I0.81 D62.17\t; set PID hotend 230C/50% fan\nM304 P114.31 I19.93 D437.00\t; set PID bed 85C\nM900 T0 K1.635 L1.72\t; Linear advance for DETAIL PETG 0.2_0.42

    And then in my specific Cura profiles, I just make sure to set the initial bed temperature to 85.1 (or whatever else triggers you use) so that it will trigger the search and replace code that I want. I also use this to set my extruder E steps, as well as PID settings. Because I have my PID values, and E-steps tuned for whatever setting that I'm using (PLA or PETG etc).


    So in the end I have about 15 different Search and Replace code to handle the various settings that I have. All hinging on this initial bed temp value.

    I even use this Search and Replace method to set different K (and L) values when I'm doing a different initial layer height for example. Bear in mind this was all for Marlin, so you'll have to modify the code to your needs.


    • Like 1
    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    • Our picks

      • New here? Get ahead with a free onboarding course
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    • Create New...