Script for setting K factor depending on filament_type and nozzle_diameter
 
Notifications
Clear all

[Solved] Script for setting K factor depending on filament_type and nozzle_diameter  

  RSS
Scottty
(@scottty)
Active Member
Script for setting K factor depending on filament_type and nozzle_diameter

Hi, I#m using prusaslicer for my selfmade dual extrusion CoreXY printer since years now.
Currently I#m trying to setup the linear advanced K factor in the printer settings, user defined start G-Code.
During some tests with LA, its k-factor depends on nozzle size and filament type. So I found no simple setting location to put his conditional K-factor.

A script should be able to solve this, but couldn't get it to work:

{If (filament_type[current_extruder] == "PET" || filament_type[current_extruder] == "PLA") then

If nozzle_diameter[current_extruder] == 0.4 then

M900 K0.05 T[current_extruder]

Endif

If nozzle_diameter[current_extruder] == 0.6 then

M900 K0.025 T[current_extruder]

Endif

Elsif (filament_type[current_extruder] == "TPU" then

M900 K1 T[current_extruder]

Else

M900 K0 T[current_extruder] ; Unknown filament type, disable Linear Advance

Endif}

Found this more readable nested if notation in https://github.com/prusa3d/PrusaSlicer/wiki/PrusaSlicer-Macro-Language

Tried also with the earlier version with {} around all if, elif, endif.

So my first question is an example for a nested if condition.

 

My second question refers to the parameter nozzle_diameter. It seems not to work in a simple condition like

{If nozzle_diameter[current_extruder] == 0.4}

Would be happy about some hints how to solve this.

Many thanks, Scottty

 

Posted : 16/01/2024 2:45 pm
Neophyl
(@neophyl)
Illustrious Member
RE:

Prusa Adds the K factor into their filament profiles.  

For example this is from the Prusament PLA filament profiles Custom Gcode field 

M900 K{if printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.6}0.12{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/ and nozzle_diameter[0]==0.8}0.06{elsif printer_notes=~/.*PRINTER_MODEL_MINI.*/}0.2{elsif nozzle_diameter[0]==0.8}0.01{elsif nozzle_diameter[0]==0.6}0.04{else}0.05{endif} ; Filament gcode LA 1.5
{if printer_notes=~/.*PRINTER_MODEL_MINI.*/};{elsif printer_notes=~/.*PRINTER_HAS_BOWDEN.*/}M900 K200{elsif nozzle_diameter[0]==0.6}M900 K18{elsif nozzle_diameter[0]==0.8};{else}M900 K30{endif} ; Filament gcode LA 1.0

{if printer_notes=~/.*PRINTER_MODEL_MINIIS.*/}
M572 S{if nozzle_diameter[0]==0.6}0.17{elsif nozzle_diameter[0]==0.8}0.12{elsif nozzle_diameter[0]==0.4}0.3{elsif nozzle_diameter[0]==0.25}0.85{else}0{endif}
{endif}

 

You cant use things like current extruder in there I think.  The placeholders and where they can be used is listed here https://help.prusa3d.com/article/list-of-placeholders_205643   

Posted : 16/01/2024 3:27 pm
Scottty
(@scottty)
Active Member
Topic starter answered:
RE: Script for setting K factor depending on filament_type and nozzle_diameter

Thank you, Neophyl,
that helped me to find the solution. 🤩
I placed the the script in the printer setting and used the filament_type. It may be less precise, but this should do it.
And in printer settings I have to add the script lines only once. 😉 

{if (filament_type[current_extruder] == "PET")}
M900 K{if nozzle_diameter[current_extruder]==0.8}0.01{elsif nozzle_diameter[current_extruder]==0.6}0.025{elsif nozzle_diameter[current_extruder]==0.4}0.05{elsif nozzle_diameter[current_extruder]==0.3}0.1{else}0.05{endif} T[current_extruder]
{elsif (filament_type[current_extruder] == "PLA")}
M900 K{if nozzle_diameter[current_extruder]==0.8}0.01{elsif nozzle_diameter[current_extruder]==0.6}0.025{elsif nozzle_diameter[current_extruder]==0.4}0.05{elsif nozzle_diameter[current_extruder]==0.3}0.1{else}0.05{endif} T[current_extruder]
{elsif (filament_type[current_extruder] == "FLEX")}
M900 K1 T[current_extruder]
{else}
M900 K0 T[current_extruder] ; Linear Advance disabled
{endif}

Thanks ans best regards, Scottty

Posted : 16/01/2024 4:47 pm
Share: