START_PRINT from SuperSlicer parameters

Hi guys

Hittig a wall here, would appreciate some help. SuperSlicer passes the parameter

INITIAL_EXTRUDER=0

and this looks like an integer to me. I define as int (tried float and even string)

{% set INIT_EXTR = params.INITIAL_EXTRUDER|default(0)|int %}

and I want to use this in an if statement:

    {% if INIT_EXTR = 0 %}
      ACTIVATE_EXTRUDER EXTRUDER=extruder
      M109 S{EXTR_TEMP}
    {% else %}
      ACTIVATE_EXTRUDER EXTRUDER=extruder1
      M109 S{EXTR_TEMP1}
    {% endif %}

I get a hard no…
Error loading template 'gcode_macro START_PRINT:gcode': TemplateSyntaxError: expected token 'end of statement block', got '='

Commented out parts of the macro at a time to confirm this if stament is the culprit…

What are you trying to achieve? Do you have multiple extruders?

Yes, two extruders. My START_PRINT gets the temperatures and initial extruder from SuperSlicer, warms up the bed and extruders (one or both), bed mesh and primes only the nozzles that are set > 0. At the end of it I want to make sure the correct extruder is active for when the print starts.

My other if statements work fine, just this particular test does not work…

You can use conditionals in the SuperSlicer markup language to have it pass the actual Klipper extruder name to your START_PRINT macro rather than trying to get your macro to parse what it gets from the slicer.

Brilliant… I will have to figure that part out. Very new to both Klipper and SuperSlier.
If I understand what you are saying I need to put summin like this into the start gcode call in SuperSlicer:

{if initial_extruder = 0} INITIAL_EXTRUDER=extruder {else} INITIAL_EXTRUDER=extruder1 {endif}

Not sure about that syntax at all. Result of a quick Google search and no access to test it right now…

Going to try this as soon as I can but still curious why my seemingly simple if statement does not work…

See

for some inspiration

Thanks @Sineos. I will have to disect that one when I have a moment to myself. But my setup is two hotends with a heater and extruder motor each. At first glance it looks like this refers to a shared heater, two extruders but I will work through these.

@vNate
From the sound of your setup, in your Klipper printer.cfg, you’d have two “extruder” modules: [extruder] and [extruder1]

You can reference the X-In / 1-out config document just for the slicer setup. That should get you basically setup. You’ll need to add in some extruder change code (retract & park gcode) to SuperSlicer for your specific printer.

@jjarosz yeah that would be ideal but I am struggling to find an example to suit my setup; all of the ones I can find are for either IDEX or dual extruder, single hotend and I am not experienced enough to translate that as yet.
So for the time being I am trying to get my inactive/ not-used-first extruder to retract before the print starts so the oozing does not smear all over my first couple of layers.

So, couple things. First, in the Klipper macro, use two equal signs:
{% if INIT_EXTR == 0 %}
That’s why you’re getting the error and will probably solve your problem.

But just in case…

Second, I’ve got a 6-in-1-out setup (so, different from yours) but this may be helpful. My SuperSlicer Start G-code block sends a PRINT_START macro with a CURRENT_EXTRUDER parameter, and that parameter is defined like this:
CURRENT_EXTRUDER={if current_extruder == "0"}extruder{elsif current_extruder == "1"}extruder1{elsif current_extruder == "2"}extruder2{elsif current_extruder == "3"}extruder3{elsif current_extruder == "4"}extruder4{elsif current_extruder == "5"}extruder5{endif}

I know that can probably be simplified but it works so I don’t mess with it.

@theophile I think you have just become my new favorite human being.
Thank you so much, I am going to implement both of these.

Works like a charm. Thanks again

@theophile

I know that can probably be simplified but it works so I don’t mess with it.

I am still new and trying to teach myself Klipper (and SuperSlicer to a certain point) so when I see things like this I immediately go “how does that work?” The variable “current_extruder” is returning a number. Couldn’t you simply tell it to put “extruder[current_extruder]?” Since there is no “extruder0” you would have to keep the first part…

CURRENT_EXTRUDER={if current_extruder == "0"}extruder{else}extruder[current_extruder]{endif}

If I did this right (and I’m still learning so feel free to provide criticism) this says if you’re using “extruder0” send “extruder” otherwise send “extruder#”. If that works, then in the future anybody stumbling across this thread can use that line of code regardless of how many extruders they have, plus it would still be viable if they add or remove an extruder without having to worry about remembering to rewrite that code. If it wasn’t for that part, I wouldn’t have bothered to necro this thread since it’s already been solved … but would this not improve the solution to the point where everybody in a similar situation can simply copy and paste that one line without needing to modify it for their number of extruders?

Probably. That’s exactly what I was referring to when I said it could be simplified. It may work perfectly just like that but I haven’t tested. The SuperSlicer variables don’t always work the way I expect them to and it can be frustrating trying to figure out why it throws errors so I haven’t felt compelled to monkey with this particular code block. Give it a shot though and let us know if it works!