Grasshopper

algorithmic modeling for Rhino

Hi !

I need to do the same as Mass Addition component but in VB. I have somthing like this:

Private Sub RunScript(ByVal x As DataTree(Of Double), ByRef A As Object)


Dim xSum As New dataTree (Of Double)


For i As int32 = 0 To x.BranchCount - 1
    For j As int32 = 0 To x.Branch(i).Count - 1
    xSum.add(x.Branch(i).item(j), New gh_path(i)) 'Here i get each item but it's wrong. I need add each item.
    Next
Next
A = xSum

The idea I guess is something like... x.Branch(i).item(0) + x.Branch(i).item(1) + x.Branch(i).item(2) + ... But how I can do if I have hundreds of branches, each with a different number of elements?

Then I need to flatten the tree result for a list. I have not tried this yet but I need it.

Thanks in advance!

Views: 966

Attachments:

Replies to This Discussion

You have to set the input to accept lists (right click > list). Then you add the items on a list together. 

Private Sub RunScript(ByVal x As List(Of Double), ByRef A As Object)


Dim xSum As double = 0


For i As int32 = 0 To x.count- 1
    xSum+=(x(i))
Next


A = xSum

Thank you very much Mateusz.
But this was only the case of the problem. My real case can not change the type of input because that tree is within the script. I have as inputs a list of doubles ( named U) and a tree of integers ( named N) which in each branch have the index of neighbourds of U (come from the points of a mesh). The next code is the real case and a attempt of reproduce the next picture (list item comp). If there are a best way to do that, please tell me how. xP

U As List(Of Double), N As DataTree(Of Integer)

Dim vecinos As New dataTree(Of Double) 'A tree as the result of List item component in the pic.

For i As int32 = 0 To U.Count - 1
    For j As int32 = 0 To N.Branch(i).Count - 1
        Dim index_vecinos As Integer = N.Branch(i).item(j)
        vecinos.add(U.item(index_vecinos), New Gh_path(i))
    Next
Next

So, besides this script surely it can simplify, I get a tree (vecinos) which I want to add each of its elements, and I think I can not do what you tell me. And then, flatten the tree to a list.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service