Getting model id from gcode macros
Hello, I'm trying to add a "repeat last print" function to klipper menu, so far so good.
I have added
@set global.last_id {{ job.id }}
to "Run before job" and
@printModelById {{ global.last_id }}
on action:repeat
But the problem is that the job.id is not the model id. Is there any way to get the model id from the macros?
I could use the model name, but don't want to run in the issue of duplicate names.
Comments
The only thing they have in common is the name. That is also how we increase printer counter - by checking if same name exists in models. So you might store job.name instead and use @printModelByName then.
But actually I wonder why, since we store last prints and you can just start last print in gui. We even store last 5 prints there and that would be independent of where it came from.
Also @repeatLastPrint 0/1/2/3/4 would be easy to add now that we have the recent prints with 0 = most recent as default.
To overcome the issue of using the incorrect model ID, you can create a custom metadata field for the model ID before starting the print job.
Add a custom G-code command in your slicer or printing software to set the model ID as metadata when starting the job.
Example:
GCode: BeforeLayer: - !SET_META MODEL_ID={model_id}
Enable metadata processing in your Klipper configuration.
[metadata] process_model_id: 1
Access the
MODEL_ID
metadata in your macros.Update your macros as follows:
@set global.last_model_id {{ metadata.get("MODEL_ID") }} @printModelById {{ global.last_model_id }}
By using custom metadata to store the model ID, you can ensure accurate tracking without the risk of duplicate names. This approach allows you to associate the correct model ID with each print job and repeat the last print accurately.
Thank you.