Grasshopper

algorithmic modeling for Rhino

Hi! I'm trying to sort the branches of a tree synchronously with a list. As I could not figure out a way to do it using gh components, I tried to write a VB script to do it. I first created a list of integers, which I am going to use as a pattern, to sort the branches (this is sort_pat). So, what I cannot do, is to add to the DataTree "n_curves" branches. The bold line is wrong, but i don't know how to write it... Any ideas?

Private Sub RunScript(ByVal curves As DataTree(Of Curve), ByVal sort_pat As List(Of Integer), ByRef A As Object)
'your code goes hereÖ
Dim x As New Integer ()
Dim y As New List (Of Curve) ()
Dim i As New Integer ()
Dim n_curves As New DataTree (Of Curve) ()

For i = 1 To sort_pat.Count
x = sort_pat(i - 1)
y = curves.Branch(x)
n_curves.Add(y)
Next
A = n_curves
End Sub

Views: 1726

Replies to This Discussion

Hi Spyros,

you cannot sort the order of branches in a DataTree, their order is already defined by the comparison between different paths.

What you can do is create a new tree that has the same data in the same lists, but different paths. You just need to make sure that the new paths you create will result in the correct order. The order in which you add them is irrelevant, the only thing that matters is the actual value of each GH_Path.

'Todo: make sure that sort_path and curves are properly matched up.

Dim n_curves As New DataTree (Of Curve) ()

For i As Int32 = 0 To sort_pat.Count-1

  Dim path As New GH_Path(sort_pat(i))

  n_curves.AddRange(curves.Branches(i), path)
Next
A = n_curves

I didn't actually test this code, I hope it at least tells you what approach to take.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks a lot, really helpful!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service