C# Array to DataTree

I looked at Peter’s work @PeterFotiadis
I see this as the way to go.
And I am also interested if it is possible to have DataTrees as arrays.

Can I go do something like
DataTree double[,]
or something maybe?
Or do I need to make the array a list?

var DataTree = new double[] { 1, 2, 3 };

question13-peter.gh (290.6 KB)


question13.gh (8.4 KB)

Look at the class definition here. To construct an DataTree object you can do this:

DataTree<double> dt = new DataTree<double>();

If you want to pass an array to the DataTree you can:

int[] array1D = new int[] { 1,2,3,4,5};

DataTree<int> dt = new DataTree<int>(array1D);

There is no implicit conversion of multidimensional arrays to DataTree tough.

2 Likes

Categorized.
Please assign your new messages to the appropriate category.
Thanks

1 Like

Grasshopper category, got it :slightly_smiling_face:

since it is about C# in grasshopper it belongs to Grasshopper Developer

1 Like

Hard to see the point of that since you’ll need to “unbox” the DT for some later usage:

Screen Shot 111

But in general you can do anything you want (as far this makes sense).

2 Likes

Ok got it :slightly_smiling_face:

Your former posts were also very helpful to me, thank you Peter :smiley: and thank you for this one, yes I am able to understand :smiley:

In general have in mind 2 things:

  1. If your Universe is R/GH use DataTrees. If not avoid them since these things are internal to GH and code’s portability (if and when your wings grow) … well … you get the gist of my message I do hope.
  2. You can put anything to anything:

Say for instance that you have a List of meshes and you want to create a LOL DataTree with the following custom type:

In fact (pointless to the max … but good for practice) do exactly that right now (MTV is the MeshTopoVertices as Array and ADJ is the Mesh Adjacency Matrix [i.e. a VV connectivity as bool [ , ]).

This means that your Tree would contain (per branch) a single custom object (of type < Something >) … that would contain a lot of useless things etc etc (Huan Valdez espresso a must for unboxing).

1 Like

Do you see what I am doing wrong? :thinking:
I looked at the examples provided by you all.


question13a.gh (16.4 KB)

WHAT a mess: you attempt to mix cats and dogs while everyone knows that cats are only compatible with blue alligators.

BUT before the politically correct (LOL) solution/salvation the 1M question is: what is your general plan/strategy? Stay in the GH bandwagon? If so you should use DataTrees for your nested collections (unless you need a List of some custom object [via a class etc] or is a matter manageable via Arrays). So List of List of List … well makes only sense if you want to do some “portable” code blah, blah.

Thank you for your fast response :slight_smile:

I want to use the collection in another c# code.
To do that, I want to make a collection from my array.
And I use arrays to use as less memory as possible.

And yes, I am the one holding catigators in my garden.

I understand the part of the class, but when I tried Matrix for example, I have not learned enough so it seems to me. Sorry :frowning:
I need to work harder.

OK, I’ll prepare a full demo case on that matter: how to use nested collections (for no reason), nested collections (for a reason) and other useless (thus usefull) things. That said Arrays may are faster … but they are a bit “static” and you can’t query them the way that you can in a List etc etc.

Screen Shot 001

1 Like

No, Peter, please, thank you but can you not explain it by a message.
If you see someone like me, let that person struggle for a bit :slight_smile:
You are too kind.

What did I do wrong in my lists? :slight_smile:
I changed the configuration a couple of times but I cannot get it working.
You were talking about classes :thinking:
I tried that, I mean, I typed that.

That meme is very funny

Is a matter of Karma, I guess. Note: only a catigator can cut the mustard (but NOT an alligacat)

Next lesson: how to do a custom object List in one C# and read it in another.

:thinking:

1. Error (CS1585): Member modifier 'public' must precede the member type and name (line 96)


question13c.gh (14.1 KB)

Er … hmm … since it works 100% OK here it should(?) work on Mars as well:
c

Tomorrow a full demo case with alligacat objects (that would work here but not there: life sucks). BTW: maybe your planet doesn’t support catigators … so try a List of objects (hope dies last):

Moral: Karma

1 Like

I will not ask you to respond this late.
But I am doing something wrong with line 100.

1. Error (CS1585): Member modifier 'public' must precede the member type and name (line 100)


question13d.gh (10.0 KB)

Well that something is that you love computers (bad/ugly/pointless things: avoid at any cost).

Anyway … this is the answer to the question that nobody asked (that’s the official definition of progress). The 3rd C# is for unboxing a List of some custom type … but the cost of unboxing, blah, blah. NOTE: cList is either a custom type thingy or something else: by what means can we prevent the C# re-executing a zillion times? (collection case: DataTree).

Collections_TheArtOfPointless.gh (118.9 KB)

Tip: simplicity is the ultimate complexity > don’t use stupid collections. For the occasion the double [ , ] is the way to go unless you want to do tricks via classic Matrix Methods (LOL) or to query things (if so use Nodes, obviously with some more elaborated way).

And now the challenge of the day: find all the colinear triads of points in less than one week.

1 Like