Drop-down Option List


#1

Hello everybody,
I’m fairly new to Rhinocommon, but have a good experience in both coding and using Rhino. I’m creating a bunch of helper commands for my CAD department and, for one of them, I’m trying to have a drop-down list option, just like the Style option for the Dim commands. I’ve been reading the APIs and trying to figure out the best way to tackle this, but it seem like I need some little input. Any help?
Thank you!


(Dale Fugier) #2

Hi Diego,

In a C# plug-in, you’d create a dialog box, using Winforms. In the dialog box, you’d add a combo box with the ‘DropDownList’ style.

– Dale


#3

Hi Dale,

I’m familiar with Winforms, my question is specific about Rhino: how can I tap into the click event of my option to show the Winform?


(Dale Fugier) #4

What ‘click’ event? I don’t understand what this means. Can you explain further what you are trying to do and why?

– Dale


#5

I’m sorry Dale, seems like I was overcomplicating the whole thing. Somehow, I was expecting the need for an event handler, which is clearly not the case. I can add an option with something like optTest = getObjectAction.AddOption("Test", "Test Value"); and then “capture” it during the RunCommand execution with the condition if (getObjectResult == GetResult.Option && getObjectAction.OptionIndex() == optTest). This really does solve my problem (which wasn’t much of a problem once figured out LOL), but there’s still a little thing that I’m not sure of: when I add my option, I can set an Option value ("Test Value" in my example); how can I change that value? Or do I have to clear all the options and re-add them back every time?
Thank you!


(Dale Fugier) #6

In general, your ‘getter’ is running inside of an endless loop, and the first thing you do in loop is call GetBaseClass.ClearCommandOptions. Then, go about setting your options.

For example:

var grain = "Rice";
var fruit = "Banana";

var go = new GetObject();
go.SetCommandPrompt("Select objects");
for (;;)
{
  go.ClearCommandOptions();

  var grain_idx = go.AddOption("Grain", grain);
  var fruit_idx = go.AddOption("Fruit", fruit);

  var res = go.GetMultiple(1, 0);

  if (res == GetResult.Option)
  {
    var idx = go.Option().Index;
    if (idx == grain_idx)
    {
      // TODO: ask about grains
      grain = "Wheat";
    }
    else if (idx == fruit_idx)
    {
      // TODO: adk about fruits
      fruit = "Pinapple";
    }
    continue;
  }

  if (res != GetResult.Object)
    return Result.Cancel;
        
  break;
}

– Dale


#7

Ok, got it. Right now my options are set in the command constructor, but it does make ways more sense that way indeed. Nothing that can’t be fixed with just a little of cut/paste LOL. Thank you so much for your help!