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.

Re: messages prompt macro

Postby Delco » Wed Dec 21, 2022 1:26 am

Thanks
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby Delco » Wed Dec 21, 2022 1:59 am

Thanks
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby Delco » Wed Dec 21, 2022 4:13 am

Thanks , how do we change the colour of the txt box and the wording on top line ?
Delco
 
Posts: 364
Joined: Tue Apr 02, 2019 4:23 am

Re: messages prompt macro

Postby DanStory » Fri Dec 30, 2022 3:50 am

That looks like a screenshot of a prompt from my M6 macro, I use "exec.Informplugin" directly in the C# macro.
Code: Select all
var status = ""; // "#" for Error, "!" for Warning title color
var button = "OK"; // "OKCancel", etc. see https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messageboxbuttons?view=windowsdesktop-7.0#fields
var title = "Title"
var message = "Message"

var result = exec.Informplugin("Messages.dll",
  string.Format("{0}{1}:{2}|{3}",
      status, button, title, messsage
  ));
DanStory
 
Posts: 22
Joined: Tue Nov 30, 2021 12:29 am

Re: messages prompt macro

Postby dezsoe » Fri Dec 30, 2022 11:21 am

I wanted to reply you before the holidays, but I had no time to finish.

The colors are fixed in the plugin. The background color of the caption is controlled by the style of the message: normal / warning / error.

The messages contain parts to control the window:

1. Show message. The string is "[*][!|#]<OK|OKCancel|YesNo|YesNoCancel>:Message" where the usual signs are: [] for optional, <> for required and | to select one of the listed parameters. "*" means that if the message is shown and reset state turns on then the message window will close. It returns cancel or no depending the window type. "!" means a warning, "#" means error, none of them is a simple message. The next part is required: you have to select the window buttons, then ":" separates the buttons from the message. The message can be one of the following: <message>|<caption|message>|[section:key]. You can write a simple message, you can set the caption and write a message or you can define a [section:key] pair to point to the current profile to read the string. The string in the profile can be in message or caption|message format. The caption is by default "Message/Warning/Error message from UCCNC" and if you set the caption then this will be replaced. You can use "[nl]" in the message to create more lines.

2. Set button number. The syntax is: "ButtonNumber:<OK,okbutton|OKCancel,okbutton,cancelbutton|YesNo,yesbutton,nobutton|YesNoCancel,yesbutton,nobutton,cancelbutton>". By default only the OK button is defined to 782 (CloseResetandQuestionForms), but you can set any button numbers. E.g. you can set input triggers to 5000 for yes and 5001 for no then call the plugin with "ButtonNumber:YesNo, 5000, 5001" to control the window from your front panel.

3. Set language: "SetLanguage:<HU|EN>". It changes the text of the buttons to English (default) or Hungarian.

Normally I use the following functions in macros to make programming more easy (copy to the end of the macro after #Events):

Code: Select all
// ================================================================================================ Dialogs
// Dialogs
// ================================================================================================

static string _macro_title = "UCCNC";
static string _error_msg = _macro_title + " error";

// ================================================================================================ ShowError

void ShowError(string str)
{
  ShowDialog(str, _error_msg, MessageBoxButtons.OK, "*#");
  // exec.AddStatusmessage(_error_msg + ": " + str);
}

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

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

  if (caption == "")
    caption = _macro_title;

  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);
}

The ShowDialog function checks if the Messages plugin is enabled. If yes then it calls it, if not then it calls the standard C# MessageBox.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Previous

Return to Macros

Who is online

Users browsing this forum: No registered users and 18 guests