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

  • Jobs and models are in deed different lists with own IDs. Actually if you print directly there is no model at all.

    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.
  • Repetier said:

    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.
    The reason is I need to physically walk to the PC to start the print in that case, it would be much nicer to have a macro something like @repeatLastPrint and bind this to a host action to repeat last print from the printer menu.
  • Now that you mention it I realize I did not add last prints to touch interface, which I will fix for next release I think.
    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.
  • The final commands will be named @printLastPrint and @queueLastPrint depending on intention, also print will queue if job is already running.
  • Thanks! Looking forward to the update.
  • Hello

    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.

Sign In or Register to comment.