Hello fellow grasshoppers,
A little context, I’m currently developing a user interface that relies heavily on the selection of rhino geometry to display custom information in the Rhino canvas.
And, it is working well, but my current issue goes beyond this usage.
I can’t delete objects or manipulate them in any way efficiently, they seem to start to flicker, even though I believe I disable redraw during the watching of the event.
I’m not the best programmer, and have grown a lot though this forum, so feel free to correct me where I’m wrong, all input is well recieved .
Here is a small video of what I’m trying to describe:
Here are the Rhino and Grasshopper files if you want to use check them out. (the code was made from parts of other posts from this great forum, I’ll try to find them to give the proper shoutout):
EventHandlerBug.3dm (55.5 KB)
EventHandlerBug.gh (6.5 KB)
Here is the code if anyone needs it:
private void RunScript(ref object GUIDS)
{
if (!_init)
{
// Keeps the layer panel from flickering…
this.RhinoDocument.Views.EnableRedraw(false, false, false);//Subscribe and Unsibscribe to events Rhino.RhinoDoc.SelectObjects -= RhinoDocOnSelectObjects; Rhino.RhinoDoc.SelectObjects += RhinoDocOnSelectObjects; Rhino.RhinoDoc.DeselectObjects -= RhinoDocOnSelectObjects; Rhino.RhinoDoc.DeselectObjects += RhinoDocOnSelectObjects; Rhino.RhinoDoc.DeselectAllObjects -= RhinoDocOnDeselectAllObjects; Rhino.RhinoDoc.DeselectAllObjects += RhinoDocOnDeselectAllObjects; _init = true; } //Output Data GUIDS = guids; //Re-Enables Draw in Rhino this.RhinoDocument.Views.EnableRedraw(true, true, true);
}
//
//Function
private bool _init = false;
List guids = new List();//Function to subscribe to selection events and retrive selection guids
private void RhinoDocOnSelectObjects(object sender, RhinoObjectSelectionEventArgs e)
{
foreach (var rhObj in RhinoDoc.ActiveDoc.Objects.GetSelectedObjects(true, false))if (!guids.Contains(rhObj.Id)) guids.Add(rhObj.Id); Component.ExpireSolution(true);
}
//Function to subscribe to deselection events
private void RhinoDocOnDeselectAllObjects(object sender, RhinoDeselectAllObjectsEventArgs e)
{
guids.Clear();
Component.ExpireSolution(true);
}