algorithmic modeling for Rhino
Hy Guys,
today I'm working on a VB-Component (in Grasshopper) which can find neighboors in datatrees . The datatree looks like this:
{0}
0:5
1:6
2:7
{1}
0:6
1:7
2:10
{3}
1:4
2:5
3:8
{...}
...
Now I want to find all paths where exactly two items are the same like in branch {1}. How can I solve this in VB? Is there an easy "search in list" class or do I have to iterate over all items by myself ??
Regards Alex
Tags:
You'll have to iterate yourself. The data stored in trees is a black box as far as the DataTree is concerned. It doesn't know how to compare or evaluate the items it carries.
The code you're looking for might look like:
Dim tree As DataTree(Of Integer) = blahblahblah
If (tree.BranchCount < 2) Then Return
Dim branch0 As List(Of Integer) = tree.Branches(0)
Dim overlap As New List(Of Integer)
For i As Int32 = 0 To tree.BranchCount -1
Dim N As Integer = 0
For Each item As Integer in tree.Branches(i)
If (branch0.Contains(item)) Then N += 1
Next
overlap.Add(N)
Next
At this point the overlap list should contain integers that tell you how many items each branch has in common with the first branch.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks David for your fast reply, I will test this code tomorrow..
Regards Alex
CODE WORKS !! Thanks David
Sorry for the newby question, but why does this not work ??
meshface = x.Faces.Item(j)
Dim vert_int_a As Integer = meshface.A
Dim vert_int_b As Integer = meshface.B
Dim vert_int_c As Integer = meshface.C
Dim vert_int_list As New List(Of Integer)
vert_int_list.Add(vert_int_a)
vert_int_list.Add(vert_int_b)
vert_int_list.Add(vert_int_c)
vert_connection_tree.Branches.Add(vert_int_list)
What I'm trying to create is a Datatree and every vert_int_list should be in a new branch ?!? There is a for-loop around of it so, this is not the problem ;-)
Regards
Alex
Every branch is associated with a specific path. You can use the Branches property to look at existing lists, but adding data should go through the Add and AddRange methods directly on DataTree.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by