Optional Option


#1

I have some command like “ShowThis”

ShowThis Library - will show my library
ShowThis Light - will show my light UI

I’m doing the following:

		Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();

		go.AddOption("Library");
		go.AddOption("Light");

		go.Get();
		if(go.CommandResult() != Rhino.Commands.Result.Success)
		{
			return go.CommandResult();
		}
		Rhino.Input.Custom.CommandLineOption option = go.Option();
		if(null == option)
			return Rhino.Commands.Result.Success;

but how to avoid of asking to choose Light or Library when no option supplied? how to make this option optional?


(Steve Baer) #2

This function returns a result which you can use to determine if an option was chosen or not.


(Dale Fugier) #3

See if this is helpful:

Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
go.SetCommandPrompt("Select option");
int library_opt = go.AddOption("Library");
int light_opt = go.AddOption("Light");
go.AcceptNothing(true);

Rhino.Input.GetResult res = go.Get();

if (res == Rhino.Input.GetResult.Option)
{
  Rhino.Input.Custom.CommandLineOption opt = go.Option();
  if (null != opt)
  {
    if (library_opt == opt.Index)
    {
      // TODO: deal with library option
    }
    else if (light_opt == opt.Index)
    {
      // TODO: deal with light option
    }
  }
}
else if (res == Rhino.Input.GetResult.Nothing)
{
}
else
{
  return Result.Cancel;
}

#4

It accepts nothing but still asks for option, I need that it should only read parameter if it’s provided, if it’s not then dont ask user about anything.


(Steve Baer) #5

I’m confused, do you want the parameters to be hidden?


(Dale Fugier) #6

I have no idea what this means. Is there an existing Rhino command that behaves this way?


#7

I guess he was trying to use RunScript to run a command with optional parameters… like this

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString();
    gs.AcceptNothing(true);
    gs.Get();
    if (gs.CommandResult() != Rhino.Commands.Result.Success)
        return gs.CommandResult();

    string parameter = gs.StringResult();
    if (string.IsNullOrEmpty(parameter))
    {
        MessageBox.Show("No parameter given");
        return Rhino.Commands.Result.Cancel;
    }
    MessageBox.Show(parameter);

    return Result.Success;
}

but his problem is that the Get() function waits an input but he dont always want to provide it… So if he use RhinoApp.RunScript(“MyCommand MyParameter”) everything is fine… but if he use RhinoApp.RunScript(“MyCommand”); the Get() function will wait an input.