# Marlin inline void gcode_M400()

Can someone show me how to add Lines to Marlin 1.1.8 ? I want to change the M400 command. In a kind like that:

M400 () { move Z + 5 if not Z MAX; Home X; printbed on MAX LENGHT}.


This coud be ported to pause and abort.

• That should be doable, but what you want is not possible if the printer hasn't been homed yet. The printer should be homed first, else Z is unknown. Note that it not smart to let known commands do something different than default. I think in version 1.1.8, the printer will not go over the limits, so no need to check for Z max. Programmatically, you need to send (G28), G91, G1 Z5 F1000, G90, G1 X0 Ymax where Ymax needs to receive the max set in the firmware first. – 0scar Oct 30 '20 at 9:30
• M400 is the final command print finished so all axes are homed long before. But i dont know how to add lines of code to this function. I tried but nothing worked :( – maf Oct 30 '20 at 10:54
• Not necessarily, motors can be disabled, there is no guarantee the printer is homed. Maybe in your case yes, but if you override a command, you should make it generic. Maybe you could add to the question why you want to do this, this seems exactly something for an end G-code script? – 0scar Oct 30 '20 at 11:29
• The End Gcode is befor M400 method of marlin so FW will execude commands after the End Gcode from slicer so i need help to add lines of code to the method of m400 in marlin firmeware – maf Oct 30 '20 at 12:06