I would like to get all objects on a specific layer. I can do this with the below code, however, the output does not change when elements move in Rhino. The component needs to be manually re-run.
I have tried
RhinoDoc.AddRhinoObject += ObjectAddedEvent;
with
public void ObjectAddedEvent(object sender, RhinoObjectEventArgs e)
{
this.ExpireSolution(true);
}
However, this refreshes the component when any object changes in Rhino, not just those on my layer.
Should I be using RhinoDoc.AddRhinoObject in a better way?
Full code below:
protected override void SolveInstance(IGH_DataAccess DA)
{
string PointsLayer = "Layer 01";
var layer_index = Rhino.RhinoDoc.ActiveDoc.Layers.FindByFullPath(PointsLayer, -1);
Rhino.DocObjects.RhinoObject[] Geom = Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(Rhino.RhinoDoc.ActiveDoc.Layers[layer_index]);
RhinoDoc.AddRhinoObject += ObjectAddedEvent;
List<Point3d> output = new List<Point3d>();
foreach (Rhino.DocObjects.RhinoObject G in Geom)
{
Point3d TempPoint = new Point3d();
GH_Convert.ToPoint3d(G, ref TempPoint, GH_Conversion.Both);
output.Add(TempPoint);
}
DA.SetDataList(0, output);
}
public void ObjectAddedEvent(object sender, RhinoObjectEventArgs e)
{
this.ExpireSolution(true);
}