Gumball Woes When Selecting Objects in Code

I am selecting objects in code from a panel button click while the Gumball is on in the UI:

private static void SelectUserData(string selection)
        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;
            string indexOption = _listGrouping.First(a => a.Value == selection).Index;
            doc.Objects.UnselectAll();
            foreach (var listId in _findHistory.ObjectIdByListId(indexOption))
            {
                Guid guidOut;
                if (Guid.TryParse(listId, out guidOut))
                {
                    doc.Objects.Select(guidOut,true,true,true);
                }
            }
            doc.Views.Redraw();
        }

The selection runs fine but the Gumball does not display after the Redraw. When I turn the Gumball off then back on in the UI the Gumball appears. When I change the layout of the view ports the Gumball appears. When I change the active view in code the Gumball does not appear.

So, it appears the Redraw or view change is only showing the selection of the objects but does not display the Gumball. I must be missing a step so please let me know how I go about making sure the Gumball comes back on after the selection if the user has set it to be on in the UI?

Best;

Steve

I have been struggling with this trying to understand why the Gumball is not displaying after annotation objects have been selected in code. One of the ways that I have tried to approach it is to create another instance of the Gumball:

           var transformObjects = new Rhino.Collections.TransformObjectList();
            var selectedObjects = doc.Objects.GetSelectedObjects(false, false).Where(ot => ot.ObjectType == ObjectType.Annotation || ot.ObjectType == ObjectType.Point);
            foreach (var a in selectedObjects)
            {
                transformObjects.Add(a);
            }

            var boundingBox = transformObjects.GetBoundingBox(true, true);

            var baseGumball = new Rhino.UI.Gumball.GumballObject();
            baseGumball.SetFromBoundingBox(boundingBox);
            var displayConduit = new Rhino.UI.Gumball.GumballDisplayConduit();
            var appearanceSettings = new Rhino.UI.Gumball.GumballAppearanceSettings();
            ///???
            displayConduit.SetBaseGumball(baseGumball, appearanceSettings);
            displayConduit.Enabled = true;
            doc.Views.Redraw();

This does create a Gumball but with the default appearance settings it seams to be unstable. If anybody knows how to set this up or has be better approach it would be appreciated.

Steve

Hi @slyon,

If the gumball is turned on - _Gumball _On then it will appears is no Rhino command is running and it one or more objects are selected. There may be other cases where it appears (too).

The GumballObject in RhinoCommon is useful if you want to define your own gumball and it’s behavior. It is not for accessing Rhino’s internal gumball.

– Dale

Dale:

When i select these objects in code and they are highlighted in the UI the Gumball does not show even though it is turned on in the UI.

Is there a way to control the UI Gumball and turn it off then back on in code? I think this will force a redraw of the Gumball in the UI.

Best;

Steve

Dale @dale ,

Is what I am seeing when selecting objects in code and the Gumball not activating like it would if you selected the objects via the UI a behavior or bug?

I think you confirmed that the UI Gumball can not be accessed and redrawing does not redraw the gumball. Please let me know if this is not the case. Even when I was trying to create a gumball for the selected Items I was able to but the one created by default was a bit wonky. If you have a code fragment that simulates the UI Gumball please point me to it so a can play around with it.

I have to think that I am not the only one in this boat or others have solved it or don’t think the behavior is a big deal.

Thanks for the help.

Best;

Steve

Hi @slyon,

If possible can you provide me a code sample, that I can run here, that reproduces what you are seeing? This is about the only I’m going to be able to assist.

Thanks,

– Dale

Dale @dale

Thanks so much for taking a look!

Command: CSProjectTemplate1Command

This should:

Create 3 annotation objects
Open a panel with a single button that has the selection code.

Sorry for the delay, I have been cutting this project up and pasting it back together to try to understand what I need to do to solve this issue.

CSProjectTemplate1.zip (101.3 KB)

@slyon - here are my mods.

Test.zip (26.9 KB)

– Dale

@dale;
Excellent, thanks a bunch for helping out.

So the crux of the issue is that you need to fire off a Command to make the selection and have the gumball work.

I have not seen a bunch of this stuff like Hiding a command before so I am off seeing other places that I can use it to simplify code.

Thanks again.

Best

Steve