DeleteRhinoObject Event for multiple objects?

Hello,
I have some code that runs on the RhinoDoc.DeleteRhinoObject Event. Of course, this becomes an issue if multiple objects are deleted as it acts on only the first object in the selection. In order to overcome this, I delete the objects, then run the code on the first instance of the RhinoApp.Idle Event. This works ok, but I was wondering if the Rhino.DeleteRhinoObject could be intelligent enough to know if there are multiple objects to handle.

thx
Luis

Strange, it should raise the event for each object separately. That is what I get IIRC. Are you using block instances?

It does raise events individually. Here is an SDK sample you can use to verify.

https://github.com/dalefugier/SampleCsEventWatcher

Was my initial post not clear? Of course it raises the event individually, and this is an issue when multiple objects are being deleted. If I run code after an object is deleted, somehow the rest of the objects do not get deleted.

Not seeing your code, I can only speculate what is going on.

But keep in mind that we don’t recommend modifying the Rhino document from an event watcher, especially one like RhinoDoc.DeleteObject.

Event watcher code should be very fast and (basically) set a flag somewhere in your application that indicates that an event of interest occurred and move on. Hence name “Event Watcher.”

Then when Rhino enters an idle state, you can check your “did something happen” flag and process the event. Use the RhinoApp.Idle event to track when Rhino enters an idle state.

In your case, you might maintain a list of object ids that were deleted. When your RhinoDoc.DeleteObject hander is called, simply add the id of the deleted object to this list. When your RhinoApp.Idle handler is called, process the deleted object list and the zero the list when finished.

Hello Dale,
Thanks, this is what I am already doing. Just wanted to know if there was a better way. Just wanted to point out that if I do run code after the DeleteObject event is fired, the rest of the objects do not delete. I am updating the text of a text entity. I will continue to run the code when I detect that RHino is idle.

Thanks.

This isn’t normal behavior. What code are you running? How can I repeat this behavior here?

It is a bit tough to share the code, but let me see if I can get bits. I am assuming that it is because I am trying to delete another object from within the DeleteObject code. The thing is that I have objects which track other objects. If one is deleted, I want the object that is tracking to be deleted as well.

namespace someTools
{
    public class someToolsPlugin : Rhino.PlugIns.PlugIn
    {
        public someToolsPlugin()
        {
            Rhino.RhinoDoc.DeleteRhinoObject += OnDeleteRhinoObject;
        }
        private void OnDeleteRhinoObject(object sender, RhinoObjectEventArgs e)
        {
            if(e.TheObject.ObjectType == ObjectType.InstanceReference)
            {
                someMethod();
                Rhino.RhinoDoc.ActiveDoc.Objects.Delete(someRhinoObj, true);
            }
           
        }
    }
}

Like I said, you shouldn’t be modifying the Rhino document from an event watcher. Make note of the event and then process later, like during an idle process or when you need to update your UI.

RhinoDoc_DeleteRhinoObject is called even if the geometry is replaced.

how do I trap only if the element was deleted using the keyboard delete button or doc,objects.delete?

Hi @HepChan,

If you press the Delete key, then the RhinoDoc.DeleteRhinoObject event will be triggered. If you move an object, then an RhinoDoc.ReplaceRhinoObject event will be triggered, followed by RhinoDoc.DeleteRhinoObject and RhinoDoc.AddRhinoObject events.

– Dale