I Hate that I don't Understand Trees

Why are they so difficult? Can someone refer me to a webinar or youtube video explaining the tools for working with trees.

Specifically, I have a definition that makes some sections of a part. There are multiple curves for each section so it makes them in a tree. I just wanted all curves for each section in one list. I’ll attach my definition that I did and it’s working but I assume there has to be a simpler way to do what I did. And I don’t even know why what I did works.


Sectionator.gh (274.6 KB)

1 Like

I just wanted all curves for each section in one list.

Flatten puts everything in one list.

Can someone refer me to a webinar or youtube video explaining the tools for working with trees.

Try
Google Search
Youtube Search
Rhinoceros Search

2 Likes

Flatten does not work to group the curves for each section together.

Capture2

I didn’t want to watch all 19,400 videos. That’s why I asked for a recommendation. But thanks anyways.

3 Likes

With Path and Branch you can get what you want enough simply.

Path, “Construct Path”, will create a path out of a list of integers, in your case it is a single number 8 > {8} , but in other cases it could build a more complex path like 5 , 3 > {5;3}.

Note that, data-trees structures like {0;0;0;0} and {0} are different.

The resulting data-tree of your BBX is too much complex to be “accessed” with a single-integer path, you need first to simplify it.
Try to not use simplify, Branch will give you an error telling you “1. Path {8} does not exist within this tree”.


Another example:
A data-tree “{x;y;z} N=w” is a country(x) with cities(y) with houses(z) with people inside.
Now it happens that there are only 3 houses, but there is only 1 country and 1 city… the structure is like:
{0;0;0} N=3
{0;0;1} N=11
{0;0;2} N=8
If you ask “Give me the persons of the second house” {1} , the program don’t know what you are talking about! It expected you to also tell on which country and which city (like a {0;0;1} ), even if there is only one of both.
So you tell it to “Simplify”… so the program can forget about the concept of “country” and “city”, and work just with houses.

Stupid example… 03:15 am here…ok i go to sleep now :upside_down_face:

3 Likes

Flatten does not work to group the curves for each section together.

Well I assumed that is what you wanted because you already have what you described?
You have 99 sections, the result of your intersection is 99 branches each with 3 curves. So they are already grouped that way.

If you need a single Branch, here are some options


Tree Branch.gh (281.4 KB)

The way google works is it puts the most popular / relevant on top. Obviously I am not suggesting to watch 19k+ videos, probably you can watch the first few. The first result seems promising if you quickly read a few of the comments / reviews / thumbs up to thumbs down ratio.

4 Likes

I feel your pain but don’t give up. Data trees do make sense.

I’ve added my ‘Tree/List Viewer’ tool to your code. You can use the ‘Branch’ or ‘Item’ outputs if you like.


Sectionator_2020May04a.gh (291.9 KB)

P.S. Try connecting Flip instead of BBX to the ‘Tree/List Viewer’ tool.

Sometimes PShift (Shift Paths) works better than flatten so I also included (but didn’t use) a “smart” version of pShift I wrote recently.

3 Likes

Hi @fpagel01 don’t worry, I know it can be frustrating but with practice it all makes sense in the end.

What you did sadly does not work, if I understood your question correctly.

The output of the Brep|Brep component already organizes data the way you want it: Each branch/list is a section, and inside there is all the curves that correspond to that section.

As a side note: Why are you not using the Contour component? Or in any case, if you want to make your custom contour with native components, it is better to use Brep|Plane component instead of
Brep|Brep for computation purposes. An intersection between a plane and a brep is lighter than between two breps.

Sectionator_re_shynn.gh (283.1 KB)

Here a video series by the creator of GH about Data Trees:

3 Likes

I feel you, still trying to wrap my head around data trees myself.

I’ve recently started to follow along with MODE LAB’s tutorial series. It’s slow going, but I guess thats needed for a topic as complex as this. Though I do not yet fully understand data trees, I’ve definately picked up some useful tricks from it.

Working with data trees (1-14):

Advanced data trees (1-12):

1 Like

GH datatrees are not this:

they are this:

Now you’re ready.

8 Likes

+100 to @ShynnSup for the suggestion of the @DavidRutten masterclass on Data Trees. It will completely supercharge your understanding of Grashopper.

Simplify was a big part of what I was missing.

Thank you. Your method is much cleaner than mine.

I’ll look at your code. Thank you

I’ve seen so many attempts to explain Trees, and all of them makes me wonder if I missed something (I always perceived them as camouflaged “Lists of Lists”). So I wonder

#1. What are Tree’s if not equivalents to “Lists of Lists” (meaning, dynamic length of the “paths”, or indexes)

#2. If Tree’s cannot directly be copied into the following Lists of Lists, what are they then?

Fig. Array’s of Arrays, or Lists of Lists (which can be essentially the same thing under the hood) of char. Indexes are grey

// Rolf

6 Likes

Sure, but you will find simplify doesn’t always work as you might need. Suirify is the safer bet in this case. Just ask @osuire :smiley:

1 Like

What’s the difference?

Check this thread: Simplify option needs to get universal

I never use Surify, I’ve always wondered why it’s necessary. I don’t mix trees of different path lengths, and if I do, I simplify the inputs. Really, I’ve never used it.

There are some cases when the zeros don’t get simplified down further, Suirify just ensures that no matter what, the paths are single number addresses in all cases. Honestly, I don’t use either much as I don’t find myself splitting out branches manually in many cases.

Suirify is beginner’s best friend. I always use it when there are operations involved two tree structures. It helps to understand better on what is happening.