Improvement of "Data Recorder Rec"

unhandled

#1

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


Objects Collider - "OnCollisionEnter" like
(David Rutten) #2

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.


#3

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


(qythium) #4

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)


#5

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


(qythium) #6

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)


#7

Whaou… couldn’t expect better


#8

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


Sticky variable alternative
More info about Timer component?
(qythium) #9

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

#10

@AndersDeleuran do you valid? :wink:


#11

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: