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
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
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)
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)
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:
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).
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 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?
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
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.
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:
thanks @AndersDeleuran will check them
You can connect the output of Data Recorder to a Data param and internalize it.