Grasshopper

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

 

Views: 49134

Replies to This Discussion

Hi Yasushi,

attached here is a simple example to iterate a tree.

- Giulio

________________

giulio@mcneel.com
McNeel Europe

EDIT: See on GitHub how to convert a GH tree in a Python list of lists, and vice versa.

Attachments:

Hi, Giulio

 

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

 

files attached

 

Any thoughts?

 

Thanks!

 

Attachments:

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

Attachments:
Thank you Giulio, That works perfectly!

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

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?

- Giulio
_______________
giulio@mcneel.com

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?

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

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 :


Attachments:

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:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service