Grasshopper

algorithmic modeling for Rhino

Hi,

This should be a relatively easy question but I can't seem to find guidance in the forum.

I'm writing a custom vb.net component that wants to output a list of a list of a list. A double nested list.

In other words, I'm looking for the GH equivalent of 

Dim x As New List(Of List(Of List(Of Double)))

For example, I might have an outer list of 10 items each containing 20 lists with 30 items inside each 2nd tier list.

Say the outgoing gh_Structure is:

Dim outgoing_Struc as new gh_structure(of gh_number)

I can't seem to figure out how I might use the "append" method to GH_Structure to insert items to specific paths to create a list of a list. 

The additional complexity is that I want to customize the indices of the outgoing list. Instead of the outer most list running straight from 0 to 9, I might want to have its indices non-sequential as {0}, {2}, {5}, {11} for example. This helps in using the "Tree Item" component downstream as these specific non-sequential indices refer to something specific upstream.

For example, with custom indices, I can pull a specific sublist by using index {11;3} which may not exists if the indices ran sequentially.

I guess the more general questions is whether anybody has pointers on creating nested trees in a custom component with specific indices? It appears that GH_Path has a "DebuggerDisplay" property which masks the internal continuously running index but this is a read only property. 

Any pointers would be helpful

Thanks.

Views: 2492

Replies to This Discussion

The GH equivalent of three nested lists would be a datatree with 3 elements in each path:

{0;0;0} → [0][0][0]

{0;0;1} → [0][0][1]

{0;0;2} → [0][0][2]

{0;1;0} → [0][1][0]

{0;1;1} → [0][1][1]

{0;1;2} → [0][1][2]

{0;2;0} → [0][2][0]

{0;2;1} → [0][2][1]

...

{1;2;2} → [1][2][2]

{2;2;0} → [2][2][0]

{2;2;1} → [2][2][1]

{2;2;2} → [2][2][2]

The first element in each path identifies the top level list, the second element the first nested list and the third element the deepest nested list. And like you said, you can change 0, 1 and 2 into whatever (non-negative) integers you want.

GH_Structure<T>.Append(data, new GH_Path(1,2,2));

--

David Rutten

david@mcneel.com

Thanks david. I should have just posted this question earlier instead of trying to figure this out myself. 

I tried "1;1;1" similar to when it's reported in the panel output but that didn't work.

So it's a "," instead of ";" as the index separator.

Is this in the GH SDK somewhere?

The comma in this case is because C# uses the comma to separate arguments in a function call. You can download the GH SDK documentation via the Grasshopper help menu.

If you want to specify the paths using standard Grasshopper notation, then you can use the FromString method:

GH_Path path = new GH_Path();

path.FromString("{0;0;1}");

That however will be a lot slower than using the appropriate constructor.

--

David Rutten

david@mcneel.com

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service