I have a list of lists 3 levels deep containing curves and I’m trying to get access to each level’s contents.
In Python this would work:
pCurves = IN[0]
firstValue = pCurves[0][0][0].StartPoint.Z
How do I reference the lists in C#? I’m able to load the full list of lists but can’t seem to find a way to step thru the various sub-lists.
First thing that comes to my mind, if someone have prettier solution please share
public static Curve GetcurveAtIndex(List<List<List< Curve >>> curves,int firstIndex,int secondIndex,int thirdIndex)
{
List<List< Curve >> firstLayer = curves[firstIndex];
List< Curve > secondLayer = firstLayer[secondIndex];
Curve targetCurve = secondLayer[thirdIndex];
return targetCurve;
}
The first thing I would do is establish why you would want such a list structure. Then the next issue is, what happens if the user inputs a list structure thats 1D, or 2D?
Generally, lists deeper than 2 dimensions is usually a sign a workflow problem which needs redressing. The only time (in 13 years of scripting + programming) I’ve needed a list structure greater than 2D was for a building scheme where I had an array storing building, floor then wall panels. However this could have easily been simplified to 2D (run the script on each building rather than all and I can drop a rank).
Finally if there is a good reason to support this depth, just write a node which takes a 1D list and let Dynamo’s lacing engine handle it for you since it works recursively on ranks greater than the one defined in the input parameter.
echoing what Thomas said, when things get that complex - think about using a dictionary or a class (in python or c#) - A dictionary can fake an object in a pinch…
Przemyslaw- Excellent! that worked for my purposes. I need to look closely at this but initial use was a success.
Thomas- I understand that the data structure may be overly complex. The first list enclosing the object is superfluous, but I need the 2 other levels to maintain the relationships between major groups.
Thanks both for your responses!
keyword :
I believe with this, you should definitely go with a dictionary OR having your own node encompass the function prior to your multi-D list.