# Any sample for 3 level of branches in DataTree Grasshopper c# dotnet code?

**URL:** <https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430>\
**Category:** Grasshopper Developer\
**Created:** [September 1, 2015, 1:21pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430 "2015-09-01T13:21:04Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsiddikee](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tsiddikee/32/148322_2.png) [@tsiddikee](https://discourse.mcneel.com/u/tsiddikee)\
**Post date:** [September 1, 2015, 1:21pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/1 "2015-09-01T13:21:04Z")

</div>

I am looking for a sample code to create three level of braches in a DataTree.  
I know I will need to use IGH\_Goo but I do not know how to use it.

I could not find GH\_Structure either. which namespace I should use?

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/557284_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [September 1, 2015, 1:38pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/2 "2015-09-01T13:38:34Z")

</div>

How about the code below. You don’t need to use IGH\_Goo or GH\_Structure, I think.

```auto
DataTree<Brep> brepTree = new DataTree<Brep>();
for (int i = 0; i < 3; ++i)
{
    for (int j = 0; j < 2; ++j)
    {
        for (int k = 0; k < 4; ++k)
        {
            GH_Path path = new GH_Path(i, j, k);
            Sphere sphere = new Sphere(new Point3d(i, j, k), 0.5);
            Brep brep = Brep.CreateFromSphere(sphere);
            brepTree.Add(brep, path);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![tsiddikee](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tsiddikee/32/148322_2.png) [@tsiddikee](https://discourse.mcneel.com/u/tsiddikee)\
**Post date:** [September 1, 2015, 1:56pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/3 "2015-09-01T13:56:43Z")

</div>

Many thanks Menno ! Really? I do not need to use Goo. But I am very interested to understand IGHGoo how it would be used in this particular case.

Many thanks ! 😄

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/557284_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [September 1, 2015, 2:18pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/4 "2015-09-01T14:18:20Z")

</div>

When you _get_ a data tree, you will use GH\_Structure like so:

```auto
GH_Structure<GH_Brep> brepTree;
da.GetDataTree(0, out brepTree);

```

I’m not sure when you would need IGH\_Goo…

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [September 1, 2015, 2:29pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/5 "2015-09-01T14:29:32Z")

</div>

Data trees have been implemented twice (and twice badly in my current opinion). Depending on what sort of code you’re writing, you’ll need to pick one of these.

1. If your code lives inside a VB, C# or Python component then you use `Grasshopper.DataTree<T>` where T can be anything.

2. If your code lives inside a Visual Studio project which compiles to a GHA plugin, then you need to use `Grasshopper.Kernel.Data.GH_Structure<T>` where T must implement `IGH_Goo`.

Grasshopper internally uses the latter and heavily relies on `IGH_Goo` for conversions, previewing, formatting and other operations. The scripting components have logic build in that can convert DataTrees to GH\_Structures and vice versa.

---

<div class="post-metadata">

**Author:** ![tsiddikee](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tsiddikee/32/148322_2.png) [@tsiddikee](https://discourse.mcneel.com/u/tsiddikee)\
**Post date:** [September 1, 2015, 4:46pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/6 "2015-09-01T16:46:05Z")

</div>

Dear David,  
It is a GHA plugin. Would you please give me a sample code for IGH\_Goo for above case. I mean I want to create a DataTree with three level of branches with IGH\_Goo.

The above one Menno shared is working in c# dot net code. But I want to learn IGH\_Goo for the same situation

Thanks a lot !

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [September 1, 2015, 8:08pm UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/7 "2015-09-01T20:08:40Z")

</div>

That question makes no sense. IGH\_Goo is not a thing in and of itself. It’s an interface that is a requirement for all data going into a GH\_Structure. What sort of data are you storing? Or are you only modifying an existing tree?

---

<div class="post-metadata">

**Author:** ![tsiddikee](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tsiddikee/32/148322_2.png) [@tsiddikee](https://discourse.mcneel.com/u/tsiddikee)\
**Post date:** [September 2, 2015, 6:43am UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/8 "2015-09-02T06:43:54Z")

</div>

Oh ! Sorry I misunderstood . I mean IGH\_Goo, what it is ? and how to use it?

😄

---

<div class="post-metadata">

**Author:** ![tsiddikee](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tsiddikee/32/148322_2.png) [@tsiddikee](https://discourse.mcneel.com/u/tsiddikee)\
**Post date:** [September 2, 2015, 7:01am UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/9 "2015-09-02T07:01:32Z")

</div>

I have no idea about IGH\_Goo, I do not know how to cook it or eat it 😃 Last 4 years you are telling me about it to use it in my code and I still do not know how it works. 😄 Because I diverted to other works. Currently we undertook a bigger project with Grasshopper. So I need deep understanding of it.  
I know how to create a 3 level branched tree now from Menno. But what is IGHGoo ? Not sure.  
My current problem is solved by Menno’s advise ebove, but I want to understand with deeper understanding about GH Data Tree. Could not find code sample which use IGH\_Goo, otherwise I would ask you specific question. I do not know, what it is for.

How are you boss? Please help me to understand the famous Goo.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/557284_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [September 2, 2015, 7:28am UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/10 "2015-09-02T07:28:31Z")

</div>

OK, this is how I understand it:

`IGH_Goo` is an interface, that is implemented by wrappers for e.g. geometry in Grasshopper, for example `GH_Brep` and `GH_Curve` are wrappers for `Brep` and `Curve`, respectively.

The class inheritance of `GH_Brep` and `GH_Curve` is this:

`GH_Brep : GH_GeometricGoo<Brep> : GH_Goo<Brep> : IGH_Goo`  
`GH_Curve : GH_GeometricGoo<Curve> : GH_Goo<Curve> : IGH_Goo`

Now, to have a tree FROM grasshopper, you need `GH_Structure<T> where T : IGH_Goo`, this means that any type that you want to put in the tree needs to implement this interface. To expand on the second example given above:

```auto
GH_Structure<GH_Brep> brepTree;
da.GetDataTree(0, out brepTree);
List<Brep> geometryOnly = new List<Brep>();

foreach(GH_Path path in brepTree.Paths)
{
    GH_Brep wrapper = brepTree[path];
    Brep geometry = wrapper.Value;
    geometryOnly.Add(geometry);
}

```

---

<div class="post-metadata">

**Author:** ![DavidRutten](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/davidrutten/32/755688_2.png) [@DavidRutten](https://discourse.mcneel.com/u/DavidRutten)\
**Post date:** [September 2, 2015, 7:42am UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/11 "2015-09-02T07:42:09Z")

</div>

Menno is correct about the specifics. The reason IGH\_Goo exists is because Grasshopper needs to be able to do certain things with its data. It needs to be able to convert it into other types of data when needed, it needs to format the data when displaying tooltips, it needs to draw geometric data in viewports during preview display, it needs to write and read data to gh files etc. etc.

IGH\_Goo provides all this functionality for types that have been designed by someone else such as bool, int, double, Line, Point3d, Curve, Brep and so on. All these types must be wrapped into GH\_BooleanGoo, GH\_IntegerGoo, GH\_NumberGoo, GH\_LineGoo, … before they are allowed to be used inside a GH\_Structure.

If you want to start using a new kind of data in Grasshopper, you’ll need to provide a new type of goo as well. It is possible to put any object into GH\_ObjectWrapper, which is a minimal implementation of IGH\_Goo for any type, but that’ll severely limit how well your data behaves.

---

<div class="post-metadata">

**Author:** ![tsiddikee](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tsiddikee/32/148322_2.png) [@tsiddikee](https://discourse.mcneel.com/u/tsiddikee)\
**Post date:** [September 2, 2015, 7:45am UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/12 "2015-09-02T07:45:43Z")

</div>

Many Thanks Menno ! Oh ! OK ! Now it is very clear to me. It is a big help !

Best regards  
😄

---

<div class="post-metadata">

**Author:** ![tsiddikee](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tsiddikee/32/148322_2.png) [@tsiddikee](https://discourse.mcneel.com/u/tsiddikee)\
**Post date:** [September 2, 2015, 7:56am UTC](https://discourse.mcneel.com/t/any-sample-for-3-level-of-branches-in-datatree-grasshopper-c-dotnet-code/24430/13 "2015-09-02T07:56:18Z")

</div>

Many Thanks David. Stupid of me. I was hearing Goo all the time and I could not link the words and I also know about GH\_Curve, GH\_Brep etc are wrapped, but I was not able to understand Goo is the interface which is wrapping the actual Rhino data… I thought Goo is something else …haahaaa. Something looks like a monster.

Many thanks to Menno and you for such a big help. I am out of a big question today 😄 … I was using goo without knowing I am using it. I understand now properly, hopefully. I could not link the words in my head previously.
