Gumball resets when changed after selection

I’m using the RhinoDoc.SelectObjects event to apply some changes to the gumball of the selected object using the _GumballRelocate command. My goal is to transform an object using the gumball and keep the last gumball position/orientation. This worked fine for Rhino 7 but stopped working with Rhino 8 because the gumball is changed to it’s previous position after my command is done. Is there any way to suppress this behavior?

        private void RhinoDoc_SelectObjects(object sender, RhinoObjectSelectionEventArgs e)
        {
            if (e.Selected)
            {
                if (e.RhinoObjects.Length == 3)
                {
                    foreach (var groupIndex in e.RhinoObjects[0].GetGroupList())
                    {
                        var group = e.Document.Groups.FindIndex(groupIndex);

                        var userData = group.UserData.OfType< RhinoCommands.GumballUserData>();

                        if (userData.Count() == 1)
                        {
                            var plane = userData.First().Plane;

                            Rhino.RhinoApp.RunScript($"_GumballRelocate {plane.OriginX},{plane.OriginY},{plane.OriginZ} " +
                                $"{plane.XAxis.X + plane.OriginX},{plane.XAxis.Y + plane.OriginY},{plane.XAxis.Z + plane.OriginZ} " +
                                $"{plane.YAxis.X + plane.OriginX},{plane.YAxis.Y + plane.OriginY},{plane.YAxis.Z + plane.OriginZ}", false);
                        }
                    }
                }
            }
        }

@Joshua_Kennedy - is this something you can help with?

If I’m understanding correctly, in Rhino 7 you were getting SelectObjects events when a gumball drag finished and then you automatically ran GumballRelocate? I’m not seeing those select objects after a gumball drag either but I also wouldn’t expect them. The selection state didn’t change. You might be better off listening to the EndCommand event for the Drag command. In EndCommand subscribe to Idle then make your update when Rhino is idling and immediately unsubscribe from Idle. Something like this.

void OnEndCommand(object sender, CommandEventArgs args)
{
      if(args.CommandEnglishName == "Drag")
      {
            RhinoApp.Idle += RhinoAppOnIdle;
      }
}

private void RhinoAppOnIdle(object sender, EventArgs e)
{
    RhinoApp.Idle -= RhinoAppOnIdle;
    Rhino.RhinoApp.RunScript("_GumballRelocate", false);
}

You’ll need to fill in your details. I understand it’s a little clunkier but I think it’ll work better than messing with the gumball during selection changes.

That Idle event trick solved it for me. Thank you!

1 Like