generative modeling for Rhino
I'm using the python component for grasshopper, and have wondered to access to the data structure which grasshopper consists.
using a=ghdoc seems to be efficient for output, but I can't get the right data structure as input.
anything will help.
I'm sure that I'm using the latest component(v0.4.1.1)
here a simple example to iterate a tree.
Thanks for the fast reply!
I will take a try and play around with your sample!
Instantiating a Data Tree seems a little trickier:
link to script
DataTree should be made specific with a simple type, like Brep, for example.
Then, layerTree.AddRange(geoms, path) can fill the tree with an enumerable (Add with a single object).
Could you give an even simpler example of how to add a datatree for output? Your first example (reading datatrees) was really clear, but I got lost on second example dealing with layernames.
Here's what I want to do:
I have a for loop in which a new list of points is created at every loop. I want to build a datatree so that each list of points is on a new branch and output from the component.
Well, I kind of figured it out (I was caught up in casting the wrong type). Still, a simple example would be great because I think I barely understand what I just did.
Hi Andrew. Yes, DataTree isn't a very simple construct by its very nature... it's easiest when it can be avoided entirely, really... a way might be to graft the list output of your script.
At the same time, maybe I can come up with a simpler example if I can use Add() and not AddRange(). Would that be appropriate in your maybe larger case?
I think it's reasonable to assume that scripters will often want to be able to create DataTrees.
Is there a way to create a DataTree with dynamic data? How could I create a DataTree that holds lists of strings, numbers, and geometry?
it is reasonable that scripters need to use DataTrees but also highly improbable that they need to construct them directly. 95% of the scripts handle lists and single items and return lists. Grasshopper then iterates the logic to create the tree. However, rare cases where full tree creation is needed do come up, so the possibility is provided by the Grasshopper SDK.
I would really not suggest to mix different data types into a single DataTree output. This might indicate instead that multiple output trees should be given as outputs. I cannot identify a single Grasshopper component that returns trees of mixed strings and numbers, for example.
In any case, you can construct a DataTree of objects
layerTree = DataTree[object]()
and this will accept any input of single data items. This is really part of the Grasshopper SDK, not something particular to Python or GhPython.
I hope this helps,
I just saw this post, but needed to address it because I had forgotten how to it myself.
Here is an example, as python code:
And here are some pictures:
It also relies on a certain type casting of the incoming data. Notice the line where I make the tree:
In this line, I declare the type of data contained in this tree. My input should reflect this choice :
I'm hoping someone can help with an example that just uses lists, as opposed to GeometryBase.
I'm working with a dynamic list of lists inside Python and am trying to output to grasshopper.
For example I have a list [[[0,1,2],[5,6],[12,13,14,15]], [[2,3],...] ]
I set up a more simplified (2d array) example in the attached image: