Grasshopper

algorithmic modeling for Rhino

Hello everyone,

I've got a DataTree with 2 levels of branches: {A;B}(items)

Number of branches at level B varies at each A level branch. Is there any way I could iterate through each A branch and count how many B branches each of them have? I don't want to know the number of items on each branch, just how many branches there are.

 

Thanks,

Bartek

Views: 966

Replies to This Discussion

These aren't really subbranches as such, it's just a flat list with those integers. You'll have to do something like this:

Dim topo As New SortedList(Of Int32, Int32)

For Each path As GH_Path in tree.Paths

  Dim A As Int32 = path(0)

  Dim N As Int32 = 0   

  If (topo.ContainsKey(A)) Then

    N = topo(A)

    topo.Remove(A)

  End If

  N+=1

  topo.Add(A, N)

Next

I didn't actually test this code, I just wanted to show the general approach.

Another way would be to create an array of integers where the indices map to A:

Dim maxA As Int32 = 0

For Each path As GH_Path in tree.Paths

  maxA = Math.Max(maxA, path(0))

Next

Dim arrA As Int32()

ReDim arrA(maxA - 1)

For Each path As GH_Path in tree.Paths

  arrA(path(0)) += 1

Next

--

David Rutten

david@mcneel.com

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service