messages prompt macro

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

messages prompt macro

Postby Delco » Mon Dec 19, 2022 10:41 pm

Hi , I am trying to find out how to get the messages plugin in V2.115 to work .

I currently have some txt and then a M0 in my gcode file to help me stop and do a certain operation before continueing and would like it to display as a message prompt when machining rather than optional stop and hving to look at the gcode to see what the instruction is.

So say I have M0 (Unscrew stock and continue) as a passthrough and comment using fusion360 in my gcode.

How do I get it to display as a popup and then wait until I hit enter before proceeding.

I assume some sort of macro is called as a passthrough ie M2005 (Unscrew stock and continue)

Any help would be apprciated.
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby fsli » Tue Dec 20, 2022 2:46 am

Delco wrote:How do I get it to display as a popup and then wait until I hit enter before proceeding. I assume some sort of macro is called as a passthrough ie M2005 (Unscrew stock and continue)

- Place the following in a text file located in the macro folder corresponding to the profile you're using, and name it using the macro number you want to use. For example, M2005.TXT

Code: Select all
var macroText = new System.Text.RegularExpressions.Regex(@"(M\d+)\s+\(([\w\s]*)\)").Match(exec.Getcurrgcodelinetext());
MessageBox.Show(macroText.Groups[2].Value, macroText.Groups[1].Value);

- Replace the M0 with the macro number followed by the comment in parenthesis. For example:
M2005 (Unscrew and continue)
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: messages prompt macro

Postby Delco » Tue Dec 20, 2022 5:18 am

Thanks

That comes up with the old version of the txt box but blank and behind the screen so you have to tab to get it up ?
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby fsli » Tue Dec 20, 2022 11:57 am

That's what happens when I throw something together too quickly. It worked for me as-is, but I forgot to force it on top of the UCCNC window. I'm using UCCNC v1.2113, though I don't know if that has any impact on whether we're seeing different results.

I don't know what you mean by, "that comes up with the old version of the txt box". You can change the macro to use the UCCNC-provided message box, but I don't know that it will change the style that you saw on the first version (this does generate a larger box on my workstation):
Code: Select all
var macroText = new System.Text.RegularExpressions.Regex(@"(M\d+)\s*\(([\w\s]*)\)").Match(exec.Getcurrgcodelinetext());
exec.Showerrormessage(macroText.Groups[2].Value, null, false);

As for it coming up blank, that would suggest you're not using a G Code line formatted as I had shown:
M2005 (Unscrew and continue)

The parenthesis are required for the pattern to match. The first version also required a space between the M2005 and the left parenthesis, but I changed that in this version in case you had omitted the space.
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: messages prompt macro

Postby dezsoe » Tue Dec 20, 2022 12:14 pm

Here is my old M56 (MSG) macro. To write a message call M56 (message). If the first character is "!" then it displays a message box (or calls the Messages plugin, of course). If you want to display a # variable then you can include it into the string. #nnn displays the #nnn value as is, #Fnnn is formatted to 4 decimals. E.g.:

M56 (Hello!) -> writes Hello! to console and status box
M56 (!Hello!) -> writes Hello! to console and status box then shows message box in Messages if the plugin is enabled or standard Windows box if not
M56 (Var 1=#1) -> writes Var 1=nnnn where nnnn is the value of #1
M56 (Formatted 1=#F1) -> writes Formatted 1=nnnn.dddd where nnnn.dddd is the value of #1 with 4 decimals

The macro:
Code: Select all
// ================================================================================================
// Print message to status window v1.0
// ================================================================================================

string myLine = exec.Getcurrgcodelinetext();
string msg = "";
int lineNo = exec.Getcurrentgcodelinenumber();
int posF = 0;
int posL = 0;
string work = "";
bool showDialog = false;

if (myLine != null)
{
  posF = myLine.IndexOf("(");
  if (posF != -1)
  {
    posL = myLine.LastIndexOf(")");
    if (posL > posF)
      msg = myLine.Substring(posF + 1, posL - posF - 1).Trim();
  }
}

if ((msg.Length > 1) && (msg[0] == '!'))
{
  showDialog = true;
  msg = msg.Substring(1);
}

if (msg != "")
{
  posF = msg.IndexOf("#F");
  while (posF != -1)
  {
    ++posF;
    work = "";
    while (Char.IsDigit((msg + "@").Substring(++posF, 1), 0))
      work += msg.Substring(posF, 1);
    msg = msg.Replace("#F" + work, exec.ivars[Convert.ToInt32(work)].ToString("F4"));
    posF = msg.IndexOf("#F");
  }
  posF = msg.IndexOf("#");
  while (posF != -1)
  {
    work = "";
    while (Char.IsDigit((msg + "@").Substring(++posF, 1), 0))
      work += msg.Substring(posF, 1);
    msg = msg.Replace("#" + work, exec.ivars[Convert.ToInt32(work)].ToString());
    posF = msg.IndexOf("#");
  }
  exec.AddStatusmessage(lineNo.ToString() + ": " + msg);
  Console.WriteLine("<M56> [Line " + lineNo.ToString() + "] " + msg);
  if (showDialog)
    ShowDialog(msg, "Message from line " + lineNo.ToString(), MessageBoxButtons.OK, "");
}

// ================================================================================================

#Events

// ================================================================================================ ShowDialog

DialogResult ShowDialog(string msg, string caption, MessageBoxButtons buttons, string style)
{
  // style: "[*][!|#]", * for cancel if reset, ! for warning, # for error

  // if (caption == "")
    // caption = "M6 - " + (ATCMode ? "ATC" : "MTC") + " - Auto probe";

  bool isMessagesEnabled = false;
  object returnValue = exec.Informplugin("Messages.dll", (object)null);
  if (returnValue is bool) isMessagesEnabled = (bool)returnValue;

  if (isMessagesEnabled)
      return (DialogResult)exec.Informplugin("Messages.dll",
          (object)(style + buttons.ToString() + ":" + caption + "|" + msg));
  else
      return MessageBox.Show(exec.mainform, msg, caption, buttons);
}

// ================================================================================================
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: messages prompt macro

Postby Delco » Tue Dec 20, 2022 9:39 pm

fsli wrote:That's what happens when I throw something together too quickly. It worked for me as-is, but I forgot to force it on top of the UCCNC window. I'm using UCCNC v1.2113, though I don't know if that has any impact on whether we're seeing different results.

I don't know what you mean by, "that comes up with the old version of the txt box". You can change the macro to use the UCCNC-provided message box, but I don't know that it will change the style that you saw on the first version (this does generate a larger box on my workstation):
Code: Select all
var macroText = new System.Text.RegularExpressions.Regex(@"(M\d+)\s*\(([\w\s]*)\)").Match(exec.Getcurrgcodelinetext());
exec.Showerrormessage(macroText.Groups[2].Value, null, false);

As for it coming up blank, that would suggest you're not using a G Code line formatted as I had shown:
M2005 (Unscrew and continue)

The parenthesis are required for the pattern to match. The first version also required a space between the M2005 and the left parenthesis, but I changed that in this version in case you had omitted the space.


yes I had ommited space - that works for message box pre V1.2115 , I am trying to work out how the new version message box works , cant find any info on it at present ?
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby Delco » Tue Dec 20, 2022 9:41 pm

dezsoe wrote:Here is my old M56 (MSG) macro. To write a message call M56 (message). If the first character is "!" then it displays a message box (or calls the Messages plugin, of course). If you want to display a # variable then you can include it into the string. #nnn displays the #nnn value as is, #Fnnn is formatted to 4 decimals. E.g.:

M56 (Hello!) -> writes Hello! to console and status box
M56 (!Hello!) -> writes Hello! to console and status box then shows message box in Messages if the plugin is enabled or standard Windows box if not
M56 (Var 1=#1) -> writes Var 1=nnnn where nnnn is the value of #1
M56 (Formatted 1=#F1) -> writes Formatted 1=nnnn.dddd where nnnn.dddd is the value of #1 with 4 decimals

The macro:
Code: Select all
// ================================================================================================
// Print message to status window v1.0
// ================================================================================================

string myLine = exec.Getcurrgcodelinetext();
string msg = "";
int lineNo = exec.Getcurrentgcodelinenumber();
int posF = 0;
int posL = 0;
string work = "";
bool showDialog = false;

if (myLine != null)
{
  posF = myLine.IndexOf("(");
  if (posF != -1)
  {
    posL = myLine.LastIndexOf(")");
    if (posL > posF)
      msg = myLine.Substring(posF + 1, posL - posF - 1).Trim();
  }
}

if ((msg.Length > 1) && (msg[0] == '!'))
{
  showDialog = true;
  msg = msg.Substring(1);
}

if (msg != "")
{
  posF = msg.IndexOf("#F");
  while (posF != -1)
  {
    ++posF;
    work = "";
    while (Char.IsDigit((msg + "@").Substring(++posF, 1), 0))
      work += msg.Substring(posF, 1);
    msg = msg.Replace("#F" + work, exec.ivars[Convert.ToInt32(work)].ToString("F4"));
    posF = msg.IndexOf("#F");
  }
  posF = msg.IndexOf("#");
  while (posF != -1)
  {
    work = "";
    while (Char.IsDigit((msg + "@").Substring(++posF, 1), 0))
      work += msg.Substring(posF, 1);
    msg = msg.Replace("#" + work, exec.ivars[Convert.ToInt32(work)].ToString());
    posF = msg.IndexOf("#");
  }
  exec.AddStatusmessage(lineNo.ToString() + ": " + msg);
  Console.WriteLine("<M56> [Line " + lineNo.ToString() + "] " + msg);
  if (showDialog)
    ShowDialog(msg, "Message from line " + lineNo.ToString(), MessageBoxButtons.OK, "");
}

// ================================================================================================

#Events

// ================================================================================================ ShowDialog

DialogResult ShowDialog(string msg, string caption, MessageBoxButtons buttons, string style)
{
  // style: "[*][!|#]", * for cancel if reset, ! for warning, # for error

  // if (caption == "")
    // caption = "M6 - " + (ATCMode ? "ATC" : "MTC") + " - Auto probe";

  bool isMessagesEnabled = false;
  object returnValue = exec.Informplugin("Messages.dll", (object)null);
  if (returnValue is bool) isMessagesEnabled = (bool)returnValue;

  if (isMessagesEnabled)
      return (DialogResult)exec.Informplugin("Messages.dll",
          (object)(style + buttons.ToString() + ":" + caption + "|" + msg));
  else
      return MessageBox.Show(exec.mainform, msg, caption, buttons);
}

// ================================================================================================


Thanks Denzoe , but that is the old version of message box , trying to get it to work with the V1.2115 message box :)
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby fsli » Tue Dec 20, 2022 11:32 pm

Can you post a screenshot of this "new" message box?
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: messages prompt macro

Postby Delco » Tue Dec 20, 2022 11:43 pm

fsli wrote:Can you post a screenshot of this "new" message box?
Attachments
message box.png
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby dezsoe » Wed Dec 21, 2022 12:00 am

Here is how it works. If the Messages plugin is enabled then the M56 macro will call that message window. Here is a sample g-code file:

Code: Select all
#100 = 1.23
#101 = 3.45
M56 (Hello operator 1!)
(Hello operator 2!)M56
M56(Hello operator 3!)G0
M56(Var 100 = #100)
M56(!Var 100 formatted = #F100, var 101 = #101)
M30

m56.png
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 16 guests

cron