Format to test for profile name in start script

What is the problem?

I want to run different start scripts depending on which printer profile is being used but I cant work out how to reference the profile name. I think the script syntax is OK, it doesn't create any errors. It should be something like:-
{% if printer_profile.name == "profile name" %}
GCODE to be actioned if the current profile has that name
{% else %}
GCODE to be actioned if not that profile name
{% endif %}
but that doesn't work. The syntax works fine but I cant get a true result for the profile name no matter what I try.

What did you already try to solve it?

Looking though the forum there are a couple of entries saying its possible but none detail the correct syntax and another that explains the printer_profile attributes have not been documented, it links to code but I just dont understand enough about the code to get the information I need.
Link to comment here.

Have you tried running in safe mode?

Not relevant

Did running in safe mode solve the problem?

Not applicable

Complete Logs

Logs show nothing.

Additional information about your setup

Octoprint Version 1.5.2
Octopi Version 0.17.0, running on Raspberry Pi 3 Model B Plus Rev 1.3

Thanks

Hello @stewl!

Hmm - now I'm curious...

Honestly, if you can afford it, take another Pi for the second printer. Benefit: two prints at the same time.

Also, printer related commands belong as much as possible into the start code of the slicer.

Take out the if clause for a minute, and enter something like this:

M117 {{ printer_profile.name }}

It could also be that the parameters are passed as a dictionary too, in which case

M117 {{ printer_profile["name"] }}

That will make absolutely sure that the name is what you expect - I can't see how that doesn't work, but debugging has to be done.

Hi @Ewald_Ikemann I have a Pi for every printer but this one is a Snapmaker 3in1 that does CNC and laser as well as print. I was wanting to use OctoPrint to at least monitor stuff or possibly run some non print work. The 3D printing is also "managed" in some strange ways. I have an OctoPrint script that actually does bed leveling and uses the probe to bed distance to set the head height - which it the standard processes don't do. When I saw you could use If statements in the GCODE scrips I thought that should be easy then I spent ages searching for the format or an example and then trying every combination I could think off. If it's not a runner I will just have to put the code into cura profiles.

Then it makes sense.

@Charlie_powell, great idea.
M117 {{ printer_profile.name }} returned the correct profile name Snap3DPrintLevel
Now what am I doing wrong with the if statement:
{% if printer_profile.name == "snap3Dprintlevel" %}
which always returns false.

It is definitely case sensitive, so the capitals would have to be exactly as it has been returned from that M117.

Thank you, sorted, correct format is indeed
{% if printer_profile.name == "Snap3DPrintLevel" %}
working just fine.
Thanks again for your help.

2 Likes