algorithmic modeling for Rhino
An engineer friend of mine has been giving me a hand with VB coding a custom component for grasshopper. The final output looks like this;
1: System.Collections.Generic.List`1[Rhino.Geometry.Point3d]
2: System.Collections.Generic.List`1[Rhino.Geometry.Point3d]
3: System.Collections.Generic.List`1[Rhino.Geometry.Point3d]
etc
I suspect this is because he wasn't aware of the DataTree structure inside grasshopper and just stored the final outputs as a list of lists, as below;
Dim allConnections As New List(Of List(Of Point3d)) 'Retrieve the list of all of the connections (now culled)
For Each vertex As MyVertex In vertexList
allConnections.Add(vertex.GetConnections)
Next
connectionListList = allConnections
Is there a quick way to convert this into a DataTree structure?
Cheers
Tags:
Here is a hacky way -
If you create an additional scripting component with one input "x" set to Item Access, and then write the following script:
A = x
It should actually output a data tree with each list in its own branch.
Otherwise, you'll need to actually write a function to populate a data tree. Here's a function in C#:
static DataTree<T> ListOfListsToTree<T>(List<List<T>> listofLists){
DataTree<T> tree = new DataTree<T>();
for(int i = 0;i < listofLists.Count;i++){
tree.AddRange(listofLists[i], new GH_Path(i));
}
return tree;
}
The hack way worked perfectly, and I ain't fussy - cheers man!
Hey Andrew,
I see you posted this a while ago (so hopefully you'll respond!), but I'm interested in utilizing the C# function you've defined here. However, I'm fairly new to C# and scripting and could use a little help regarding the particulars of how this is used.
Would I be correct that one should place the function in the "<custom additional code>" segment at the bottom of the scripting environment? If so, what is the syntax that should be used in the main body of the script to access said function?
Thanks in advance (if you see this!),
Austin
Perfectly clear, thank you!
Was about to task same question. Thank you!
is a similar concept, written in Python, to transform arbitrarily-deep trees to arbitrarily nested lists. I am linking this here to help people find it.
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
this is a really smart awesome solution ( I mean the hacky)
save a lot of work.
thanks a lot
yesterday i met similar problem likes urs~
and a kind man (id:David Stasiuk)help me to solve itin VB
hope it helpful~~
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
© 2024 Created by Scott Davidson. Powered by