Skip to content

Instantly share code, notes, and snippets.

@sbaer
Created March 23, 2012 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbaer/2175229 to your computer and use it in GitHub Desktop.
Save sbaer/2175229 to your computer and use it in GitHub Desktop.
Using Custom Messages in a Get operation
// Your "get" class will have code that looks like.
var go = new Rhino.Input.Custom.GetOption();
var optDbl = new Rhino.Input.Custom.OptionDouble(12, 0,100);
go.SetCommandPrompt("Give me an option");
go.SetCommandPromptDefault("");
go.AcceptCustomMessage(true); // NEW!!
while (true)
{
// need to clear and reset the command options every iteration because
// Rhino doesn't know that it needs to update the option string
go.ClearCommandOptions();
go.AddOptionDouble("x", ref optDbl);
var result = go.Get();
if( result== Rhino.Input.GetResult.Option)
continue;
if( result==Rhino.Input.GetResult.CustomMessage)
{
// NEW - custom message was sent from somewhere
object msg = go.CustomMessage();
if (msg != null)
{
if (msg is int)
optDbl.CurrentValue = (int)msg;
else if (msg is double)
optDbl.CurrentValue = (double)msg;
}
continue;
}
break;
}
////////////////////////////
// Somewhere else in code...
// Probably your button click event handler
...
private void Button_Click(object sender, EventArgs e)
{
// NEW - send a custom message from anywhere and your Get()
// will retrieve it as a custom message
Rhino.Input.Custom.GetBaseClass.PostCustomMessage(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment