Rhino Command AddOption GetString Update

Hello Everyone,

I’m working on a command with multiple option inputs, among them also one which prompts the user to enter a string. The way I’m doing this is with an AddOption which when selected calls a GetString class.

if (res == Rhino.Input.GetResult.Option)
{
if (go1.OptionIndex() == OptionsIndices[0])
{
if (OutPrefixOp.GetLiteralString() == GetResult.String)
{
UserPrefix = OutPrefixOp.StringResult();
}
}

}

After the string is entered, the command goes back to the “main” options line. The problem with this approach is that it doesn’t automatically update the AddOption parent value of the GetString like AddOptionInteger / Boolean / List do when the command is still active. It only shows the updated inputs when the command is run again. Is there a way of making the AddOption update its value while the command is running?

Thanks,
Radu

Hi @Radu,

Can you please post something that we can run here that reproduces what you are seeing? The small code snippet isn’t enough for me to understand what you are doing.

Thanks,

– Dale

Hello Dale,

Very sorry for the late reply. I’m attaching an rhp file and copying the code below:

using Rhino;
using Rhino.Commands;
using Rhino.Input;
using Rhino.Input.Custom;
using System;

namespace GetStringQuestion
{
public class GetStringQuestionCommand : Command
{
public GetStringQuestionCommand()
{
Instance = this;
}

    public static GetStringQuestionCommand Instance
    {
        get; private set;
    }

    public override string EnglishName
    {
        get { return "GetStringQuestionCommand"; }
    }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        GetObject go = new GetObject();

        go.SetCommandPrompt("Please Select Objects");

        string pathExcel = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments);
        string worksheetName = "Elements_DetailedView";
        string layerStruct = "Default::Default::";

        GetString outFilepath = new Rhino.Input.Custom.GetString();
        outFilepath.SetCommandPromptDefault("Enter Excel Filepath");

        GetString outWorksheet = new Rhino.Input.Custom.GetString();
        outWorksheet.SetCommandPromptDefault("Excel Worksheet Name");

        GetString outLayers = new Rhino.Input.Custom.GetString();
        outLayers.SetCommandPromptDefault("Please Enter Layer Path, using :: between parent/child layers and ending with ::");

        string UserPath = pathExcel;
        string UserWorksheet = worksheetName;
        string UserLayers = layerStruct;

        int opFilepath = go.AddOption("FilePath", UserPath);
        int opWorksheet = go.AddOption("Worksheet", UserWorksheet);
        int opLayers = go.AddOption("LayerPath", UserLayers);

        while (true)
        {
            GetResult res = go.GetMultiple(1, 0);

            if (res == Rhino.Input.GetResult.Object)
            {
                doc.Views.Redraw();
            }
            else if (res == Rhino.Input.GetResult.Option)
            {
                var option = go.Option();

                if (option.Index == opFilepath)
                {
                    if (outFilepath.GetLiteralString() == GetResult.String)
                    {
                        string temp = outFilepath.StringResult();
                        temp.Trim('"');
                        UserPath = System.IO.Path.GetFullPath(temp);

                    }
                }
                else if (option.Index == opWorksheet)
                {
                    if (outWorksheet.GetLiteralString() == GetResult.String)
                    {
                        UserWorksheet = outWorksheet.StringResult();
                    }
                }
                else if (option.Index == opLayers)
                {
                    if (outLayers.GetLiteralString() == GetResult.String)
                    {
                        UserLayers = outLayers.StringResult();
                    }
                }
                continue;
            }

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

            break;
        }

        return Result.Success;
    }
}

}

Thanks,
Radu

GetStringQuestion.rhp (39.5 KB)