Optional Option

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


		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?

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

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

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)
  return Result.Cancel;

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.

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

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

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

    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.