C# scripting: selection highlight lost when toggling option

I want to use GetObject.GetMultiple for the user to make a selection and be able to set an option, in this case an OptionToggle.
In the code below everything works as expected, except when toggleing the option after a selection has been made, the selection loses the yellow highlight. Its only a visual thing, the correct selection will be returned, but i would like the selection to stay highlighted even when changing an option, like it is the case with native Rhino commands.

Any ideas? Here is what i have so far:

using System;
using Rhino;

var activeDoc = Rhino.RhinoDoc.ActiveDoc;
bool stickyBool;

if(activeDoc.RuntimeData.ContainsKey("stickyBool"))
    stickyBool = (bool)activeDoc.RuntimeData["stickyBool"];
else
{
    activeDoc.RuntimeData.Add("stickyBool", true);
    stickyBool = true;
}

var go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select Objects");
go.EnableClearObjectsOnEntry(false);

var stickyBoolOption = new Rhino.Input.Custom.OptionToggle(stickyBool, "False", "True");
go.AddOptionToggle("ScriptOptionToggle", ref stickyBoolOption);

for(;;)
{
    var get_rc = go.GetMultiple(1,0);

    if(go.CommandResult() != Rhino.Commands.Result.Success)
        break;
    else if (get_rc == Rhino.Input.GetResult.Option)
    { 
        stickyBool = stickyBoolOption.CurrentValue;
        activeDoc.RuntimeData["stickyBool"] = stickyBoolOption.CurrentValue;
        continue;
    }
    break;
}
Console.WriteLine("Number of objects selected: " + go.ObjectCount.ToString());

By the way, i just tried to put this exact code into a command plugin and load the RHP, and it works as expected. In the script editor it doesn’t. Strange thing…

8.10.24226.13001, 2024-08-13

When this Python 2 script
from __future__ import absolute_import, division, print_function, unicode_literals

#! python 2

import Rhino.Input as ri


def main():

    go = ri.Custom.GetObject()
    go.SetCommandPrompt("Select objects")

    go.EnableClearObjectsOnEntry(False) # Default is True.
    go.EnableUnselectObjectsOnExit(False) # Default is True.
    go.DeselectAllBeforePostSelect = False # Default is True.

    optToggle = ri.Custom.OptionToggle(False, 'No', 'Yes')

    go.AddOptionToggle("ToggleMe", optToggle)

    bFirstRun = True

    while True:
        res = go.GetMultiple(minimumNumber=1, maximumNumber=0)

        if res == ri.GetResult.Cancel:
            go.Dispose()
            print("No objects were selected.")
            return

        if res == ri.GetResult.Object:
            objrefs = go.Objects()
            go.Dispose()
            print("{} objects were selected.".format(len(objrefs)))
            return

        if bFirstRun:
            go.EnablePreSelect(False, ignoreUnacceptablePreselectedObjects=True) # Default is True.
            bFirstRun = False


if __name__ == '__main__': main()

is executed in the Script Editor, post-selected objects are also/still losing their highlighting when the option is selected, even though the objects remain in Custom.GetObject’s Objects. (The same occurs when the script is executed as Python 3.)

When the script is executed via _-ScriptEditor _Run, there is no printed output.

The objects both remain highlighted and in Custom.GetObject’s Objects with:

  • _-RunPythonScript
  • Execution inside Rhino Python Editor
1 Like

Thank you for reporting this and the example scripts. I got it logged here and will fix

RH-83555 Selected objects lose highlight after script run