generative modeling for Rhino
Hi,
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)
Permalink Reply by Giulio Piacentino on May 12, 2011 at 3:04pm Hi Yasushi,
here a simple example to iterate a tree.
- Giulio
________________
giulio@mcneel.com
McNeel Europe
Permalink Reply by Yasushi Sakai on May 15, 2011 at 8:02pm Hi, Giulio
Thanks for the fast reply!
I will take a try and play around with your sample!
Permalink Reply by Benjamin Golder on June 10, 2011 at 4:02pm Instantiating a Data Tree seems a little trickier:
link to script
files attached
Any thoughts?
Thanks!
Permalink Reply by Giulio Piacentino on June 10, 2011 at 4:53pm 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).
- Giulio
_____________
giulio@mcneel.com
McNeel Europe
Permalink Reply by Benjamin Golder on June 10, 2011 at 5:39pm
Permalink Reply by Andrew Kudless on February 6, 2012 at 3:23am Hi guys,
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.
Thanks,
Andrew
Permalink Reply by Andrew Kudless on February 6, 2012 at 3:35am 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.
Permalink Reply by Giulio Piacentino on February 8, 2012 at 3:51pm 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?
- Giulio
_______________
giulio@mcneel.com
Permalink Reply by Benjamin Golder on March 4, 2012 at 1:34pm 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?
Permalink Reply by Giulio Piacentino on March 5, 2012 at 6:27am Hi Benjamin,
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,
- Giulio
________________
giulio@mcneel.com
Permalink Reply by Benjamin Golder on March 4, 2012 at 1:30pm Hi Andrew,
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:
https://gist.github.com/1974640
And here are some pictures:
This particular script relies on accessing a list of incoming data, (because it makes a branch for each item, basically it performs a graft.
It also relies on a certain type casting of the incoming data. Notice the line where I make the tree:
DataTree[Rhino.Geometry.GeometryBase]()
In this line, I declare the type of data contained in this tree. My input should reflect this choice :
Permalink Reply by 2crunchy on September 10, 2012 at 4:35pm 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],[6]...] ]
I set up a more simplified (2d array) example in the attached image:
© 2013 Created by Scott Davidson.
Powered by