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
1 Like

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