Grasshopper

algorithmic modeling for Rhino

Hi guys,

I am just looking is something that can make my life easier (spare me a few lines of code or more importantly avoid debugging for cases I haven't yet considered. Lets say I have two inputs. One is a Datatree of Point3d and the other a flat list of doubles. I want the output list of doubles to inherit the structure of the points Datatree.I have managed to do that in the above cases. However, I feel that there must be a generic and  easier way than just iterating through the input datatree. Maybe with the .cleardata member??

case A:

Dim outputree As New Datatree(Of System.Object)
Dim i,j As Int32

For i = 0 To x.branchCount - 1
For j = 0 To x.branch(0).Count - 1
outputree.Add(y(i + (j * x.branchCount)), x.Path(j))
Next
Next

A = outputree

case B:

Dim outputree As New Datatree(Of System.Object)
Dim i,j As Int32
Dim sumP As Int32 = 0

For i = 0 To x.branchCount - 1
For j = 0 To x.branch(i).Count - 1
outputree.Add(y(j + sumP), x.Path(i))
Next
sumP += x.branch(i).Count
Next

A = outputree

The second case is kind of universal. Works in most of the cases.

Thanks in advance,

M.

Views: 498

Attachments:

Replies to This Discussion

Hi Marios,

    Dim outputree As New Datatree(Of Double)
Dim sumP As Int32 = 0

For Each p As GH_Path In x.Paths
outputree.AddRange(y.GetRange(sumP, x.Branch(p).Count), p)
sump += x.Branch(p).Count
Next

A = outputree

Its not writing much less code but sometimes ok...

if not just use this custom function with type conversion like here:

 

  Public Function Topology(Of T, N)(ByRef data As DataTree(Of T), ByRef y As List(Of N)) As Object
Dim newOne As New DataTree(Of N)()
Dim sumP As Int32 = 0
For Each p As GH_Path In data.Paths
If sumP > y.Count Then
Exit For
End If
Dim count As Integer = If((sumP + data.Branch(p).Count > y.Count), y.Count - sumP, data.Branch(p).Count)
newOne.AddRange(y.GetRange(sumP, count), p)
sumP += data.Branch(p).Count
Print(data.Branch(p).Count)
Next
Return newOne
End Function

 

 

And then call it

 

A = Topology(x, y)

I've added the scripts to your gh definition
Attachments:

Cheers Florian,

I have also made this into a function just to use it over and over again. Thanks again,

M.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service