scm_comp
(Scm Comp)
August 26, 2018, 3:51pm
1
Hi,
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?
Thanks.
RIL
(Rolf)
August 26, 2018, 5:50pm
2
scm_comp
(Scm Comp)
August 26, 2018, 9:11pm
3
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;
Component.ExpireSolution(true);
}
void HandleAddedObject(object sender, RhinoObjectEventArgs args)
{
addedObj = args.TheObject;
Component.ExpireSolution(true);
}