algorithmic modeling for Rhino
I have a tree of : system.collections.generic.list1[rhino.geometry.line]
how can convert it to GH_DataTree<Line> inside grasshopper C#
Tags:
Hi Abdulmalik,
I'm a bit confused. When you say a "tree of : system.collections.generic.list1[rhino.geometry.line]", what does that mean?
Thanks David for your quick reply..
well i have a c# library that generate a DataTree<List<Line>> and it comes out as shown in the panel
I have tried to access it as System.Object, but i am missing something in the parsing process probably !
I am just trying to extract this long tree to lists into lines
i was wondering how can i differ between
GH_Structure<List<Line>> and DataTree<List<Line>>
i am having second thoughts on the tree type, i am afraid it might be GH_Structure !!
ok , i solved it with a very strange line ..
A = x;
but x is an Item Access of System.object
Grasshopper knows what a Rhino.Geometry.Line is, but it does not understand what it is supposed to do with a List<Line>. It'll store it in a data tree, but beyond that it cannot handle the concept.
The Script components however do have a very coarse understanding of collection classes, when you output a type which implements IEnumerable<T> and which is not already a 'known' type* it will try to unpack that collection and put the entire collection into a data tree ranch. This is probably why A = x; worked for you because it allows the script component to inspect and unpack the lists.
DataTree and GH_Structure are annoyingly similar yet non-overlapping classes. GH_Structure is used by Grasshopper itself to store data, DataTree is a version that was made specifically for the use inside script components. This part of the SDK is a mess but there's nothing we can do about it at this point.
If you want to convert a DataTree<List<Line>> into a Data<Line>, you have to decide whether you want each list to end up being a unique branch, or whether you're happy to just merge all the lines in all the lists that already share a branch. The code will look a little bit different in each case.
* Known types include Polyline which is an IEnumerable<Point3d>, string which is an IEnumerable<char> and so on, we assume these types need to remain intact.
Thanks David,
This is still very strange to automatically unpack data without any reference stating that this is possible :) , it is good to know , but it was a surprise to try such a silly line and get results !!
Anyway if i will convert DataTree<List<Line>> into a Data<Line>, i would always keep each list as a branch, but this would not be much of an issue now since i was having trouble converting "system.collections.generic.list1[rhino.geometry.line]" into List<Line> in the first place
Many thanks,
Malik
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2025 Created by Scott Davidson.
Powered by