Improvement of "Data Recorder Rec"

Would it be possible to have as input those parameters in order to include and have more control on data recorder inside loop or other definition?

“Boolean” Start recording
" Boolean" Detroy data
"Number" Data limit

2 Likes

Possible yes, probably not going to happen for GH1.
If you need this for simple data types (text, colours, points, numbers) I can make you a C# component, if you also need it to work for more complex data types then a C# solution may be a bit lossy.

No this is mainly the data types i would like to records numbers, points, and “would be great” plane surface and Breps :wink:

4-line implementation in GhPython, works with any data type -

from scriptcontext import sticky
if reset or 'x' not in sticky: sticky['x'] = []
if enable and not reset: sticky['x'].append(x)
x = sticky['x'][-limit:] if limit > 0 else sticky['x']

improved_datarecorder.gh (5.9 KB)

(On a side note, why aren’t we allowed to upload .ghuser files on this forum? Could be useful for ‘snippets’ like these)

3 Likes

Great! Many Thanks!
Will have to look deeper in GhPython! But at first Grasshopper was visual programming for guys like me!

Update: Use this version instead with the input set to Data Tree access, the previous one was only good for single-item inputs.

from scriptcontext import sticky
from Grasshopper import DataTree
if reset or 'x' not in sticky: sticky['x'] = DataTree[object]()
if enable and not reset: sticky['x'].MergeTree(x)
if limit > 0:
  for branch in sticky['x'].Branches:
    if branch.Count>limit:
      branch.RemoveRange(0,branch.Count-limit)
x = sticky['x']

improved_datarecorder.gh (12.3 KB)

2 Likes

Whaou… couldn’t expect better

Note that using a non-unique sticky key (i.e. "x") means that another instance of this GHPython component (or anything else that can access the sticky) can mess with this sticky value (leading to all sorts of potential trouble). A couple of ways around this:

  1. Get the guid of the GHPython component and append this to the key (example here), making the key value unique to the specific GHPython component instance (meaning you can copy/paste it).

  2. Or better yet: Use the if “foo” not in globals() method for creating a persistent variable (covered here and here).

2 Likes

Ah, I hadn’t realized that sticky was shared between all the components :open_mouth: Thanks!

Updated-again code:

from Grasshopper import DataTree
if reset or 'rec' not in globals(): rec = DataTree[object]()
if enable and not reset: rec.MergeTree(x)
if limit > 0:
  for branch in rec.Branches:
    if branch.Count > limit:
      branch.RemoveRange(0, branch.Count - limit)
x = rec
3 Likes

@AndersDeleuran do you valid? :wink:

1 Like

And the EditPythonScript editor! The sticky can be super useful for that reason, but may also cause all sorts of hard to debug problems. With great power… and such :wink:

Hi,
thanks for your python-script. it helped me a lot.
just a little question which may solve my issue is how can I reset the recorder component after a specific iteration in my loop? for example, I need to use this component at the output of the Anemone plug-in and I want to reset the whole Data before starting the loop again but I can’t use the same toggle bottom for both because the data recorder component Reset the data in each iteration before complete the entire loop! and I need to only reset the data before starting over the loop at the time I press the true toggle in my anemone input!
thanks.