Update based on add/delete event


I’m currently using a 10s timer to get an update on objects added/deleted from a layer. This is horribly inefficient as the number of objects grows. I need to get rid of the timer.

The goal is to determine when an object is added or deleted from a layer only then run the update. Much like the way the timer works but for events.

Is there any C# code to emulate this behavior?


Have you looked in RhinoCommons documentation?

https://developer.rhino3d.com/api/RhinoCommon/html/E_Rhino_RhinoDoc_LayerTableEvent.htm , and

// Rolf

Thank you Ril,

I’ve got the code to notify me when objects are added to a layer I should be set from here.

Here is the basic code, I’ll clean it up some more now I know it works.

private void RunScript(int LayerNumber, ref object LayerEvent, ref object LayerIndex, ref object AddedObj)
RhinoDoc.LayerTableEvent -= HandleLayerEvent;
RhinoDoc.LayerTableEvent += HandleLayerEvent;
RhinoDoc.AddRhinoObject -= HandleAddedObject;
RhinoDoc.AddRhinoObject += HandleAddedObject;
if(addedObj != null)
if(addedObj.Attributes.LayerIndex == LayerNumber)
LayerEvent = evtType;
LayerIndex = layerIndex;
AddedObj = addedObj.Id;


LayerTableEventType evtType;
int layerIndex;
RhinoObject addedObj = null;

void HandleLayerEvent(object sender, LayerTableEventArgs args)
evtType = args.EventType;
layerIndex = args.LayerIndex;

void HandleAddedObject(object sender, RhinoObjectEventArgs args)
addedObj = args.TheObject;