How can I flush data recorder components with Metahopper?

I’d like to flush data recorder components with Metahopper because I’ve got a lot of monitoring to do on booleans that control data flow in my definition.
Getting bored clicking the “X” button at each go…
“Expire” doesn’t work as it just adds a “false” to the component’s output list.
I’ve tried “Set value” with a “False” boolean, it’s the same.
“Set value” with an empty list does nothing…

1 Like

Hi Osuire,

The script I’ve posted earlier probably originated from this thread: https://discourse.mcneel.com/t/improvement-of-data-recorder-rec
I thought I did this myself but for that the code does look too similar :grinning_face_with_smiling_eyes:

2 Likes

You need to add this script component in a group with the DataRecorder components you want to control:

private void RunScript(bool recording, bool reset)
{
  var drs = FindDataRecsInCurrentGroup();
  foreach(GH_DataRecorder dr in drs)
    if (dr.RecordData != recording)
    {
      dr.RecordData = recording;
      dr.ExpireSolution(true);
    }
  if (reset)
    foreach(GH_DataRecorder dr in drs)
    {
      dr.DestroyRecordedData();
      dr.ExpireSolution(true);
    }
}
// <Custom additional code> 
private List<GH_DataRecorder> FindDataRecsInCurrentGroup()
{
  var groups = GrasshopperDocument.Objects.OfType<GH_Group>().Where(gr => gr.ObjectIDs.Contains(Component.InstanceGuid)).ToList();
  var output = groups.Aggregate(new List<GH_DataRecorder>(), (list, item) =>
  {
  list.AddRange(GrasshopperDocument.Objects.OfType<GH_DataRecorder>().
  Where(obj => item.ObjectIDs.Contains(obj.InstanceGuid)));
    return list;
  }).Distinct().ToList();
  return output;
}

DataRecorders.gh (5.1 KB)

6 Likes

You guys are amazing !