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


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'] (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)


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:
x = sticky['x'] (12.3 KB)


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).


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

@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:

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!

Thank you for your python script it helped me on our project very much but I only have a question. Is there a possibility that in every input of x can be stored as branch, like branch 0 is the newly recorded data and branch 1 was the recorded data from the previous run?

if i am not wrong all the data recorders will delete the data once i exit the rhino.
Is there a way to store them even after i close the rhino window ,so that after a week or sometime i can come and play with the stored values .Mostly, my data will be a tree of num and text.
I know for the fact that we can save the results in csv or excel and retrieve them back. But i want them to be in gh itself.
Thanks in advance.

You can write/read to the Grasshopper document ValueTable using a scripting component. Here’s a quick GHPython component example that uses JSON to cast the value types: (3.1 KB)

1 Like

thanks @AndersDeleuran will check them

1 Like

it worked amazing.i even rewrote the script a bit using metahopper and datadam to add values to the existing data.

You can connect the output of Data Recorder to a Data param and internalize it.