I have a few hand-written gcode files which I use for specific things like vacuuming the table, resurfacing, drilling mounting holes, etc.
These require that the machine be in a specific configuration before running, and that isn't my typical go-to configuration for working. I wanted a way to force myself to think about the machine, and to remind myself of the requirements for a gcode file before running. So, I build this macro. It pulls lines of text from the gcode file and displays them in a modal dialog that requires a YES or NO answer.
I hope it's useful to someone...
// Display a MessageBox from inline text in a gcode file.
//
// The message follows the macro invocation, each line
// will be displayed in a YES/NO MessageBox.
// The first line will be used as a caption for the box,
// the other lines will be its body.
// MessageBox lines are recognized by an asterick in the third
// character of the line. A limit of six lines is arbitrarily
// imposed to prevent unintentional run-aways.
//
// For example, my hand-crafted gcode file to vacuum my table has this as
// its first lines:
//
// m20904
// ( * VACUUM THE TABLE)
// ( * Assuming the origin is at machine 0,0)
// ( * The head is moved across the table without changing the Z position)
//
// Rick VanNorman, 05October2019
// rick@neverslow.com
int n = exec.Getcurrentgcodelinenumber()+1;
int lim = n+6;
string msg = "";
string tmp = "";
string caption = " PAY ATTENTION!";
tmp = exec.Getgcodelinetext(n++);
if (tmp[2] != '*') {
MessageBox.Show(exec.mainform,"No inline gcode message to display",caption);
return;
}
caption = tmp.Substring(4,tmp.Length-5);
while (n<lim) {
tmp = exec.Getgcodelinetext(n++);
if (tmp[2] != '*') break;
msg = msg + tmp.Substring(4,tmp.Length-5) + "\n";
}
System.Windows.Forms.DialogResult result = MessageBox.Show(exec.mainform,msg,caption,MessageBoxButtons.YesNo);
if (result != System.Windows.Forms.DialogResult.Yes) {
exec.AddStatusmessage("gcode aborted");
exec.Wait(250); // Wait 1/4 sec
exec.Stop();
exec.Callbutton(144); // Put machine in Reset mode
return;
}