GetObject to accept strings and transparent commands

rhinocommon

#1

HI,
We are trying to create a command that has an input as a string but we would also like to have the ability of running transparent commands. The issue seem to be that GetObject.AcceptString() and GetObject.EnableTransparentCommands() seem to exclude one another. If we enable the string reading from command line we automatically exclude the possibility of executing commands. Is there something I am missing or is it a limitation of the infrastructure?

The example code would be:

var go = new GetObject();
go.AcceptString(true);             //< As we want to read string from command line
go.EnableTransparentCommand(true); //< which is active by default it seems
var res = go.Get();                //< If a command is run res == GetResult.String

Thanks
Alberto


(Menno Deij - van Rijswijk) #2

I guess this is not so much a limitation of the infrastructure, as it is the fact of entering a string: how is Rhino supposed to know that the string you entered is a command or a user-input string? The two options are indeed exclusive of each other.
What you can do, though, is add a string-option to your GetObject like so:

GetObject go = new GetObject();
      
go.AcceptNothing(true);
go.EnableTransparentCommands(true);


string value = "Initial Value";
while (true)
{
  go.ClearCommandOptions();
  int optIndex = go.AddOption("UserString", value);

  GetResult gr = go.Get();
  if (gr == GetResult.Cancel)
    return Result.Cancel;

  if (gr == GetResult.Object || gr == GetResult.Nothing)
    break;
  if (gr == GetResult.Option)
  {
    if (go.OptionIndex() == optIndex)
    {
      GetString gs = new GetString();
      gs.SetCommandPrompt("Enter value");

      // use GetLiteralString to support entering spaces
      GetResult gr2 = gs.GetLiteralString();
      if (gr2 == GetResult.String)
      {
        value = gs.StringResult();
      }
    }
  }
}

RhinoApp.WriteLine($"Last entered value is {value}");

return Result.Success;

#3

Hi Menno,
I worked it around by using Command.IsCommand and I filter it from a list of command that I want to allow the user during the execution of the GetObject. Thanks for the reply

Cheers
Alberto


(Menno Deij - van Rijswijk) #4

Hah, nice one, I didn’t know that was possible!