Do Macros affect the following g-code run?

Does running a macro affect the following gcode run?
E.g. if I use the G91 (INCREMENTAL MODE) and G20 ( INCH MODE ) in my macro… does that set any global values in gsender that if my g-code does not use or re-set would be used by said gcode?

E.g. if I were to use G20 in my macro, but my g-code is in millimeters, and does not set G21 to set coordinates to mm (I guess it always should, but for the purposes of this question let’s assume that’s a thing), would that mess up the g-code and change mm to inches?

Thanks!

@NCNC I’m going to leave the answer to more knowledgeable members. However, I do have a question about your premise. If the gcode does not include the G21 setting, how do you conclude that all of the gcode commands in the file are in millimeters?

Without a designated unit in gcode, Grbl will default to mm mode.

@NCNC
You can save the current state at the start and restore that state at the end of your macro.
See:

2 Likes

Thank you NeilFerreri! much appreciated :slight_smile:

@NeilFerreri Tks, Neil. I was hoping that you would respond to this question.

For my education, though, to go back to the original question, let’s assume that the gcode did have a G20 command at the start. I run a macro that sets measurements to G21, the run the gcode. The gcode will run in mm, correct? The macro will have no effect.

If you change the unit mode to mm in the macro, it will persist until it is changed back. It’s good practice in macros to save and restore the modes, including unit.
So, be careful

3 Likes