First time poster, long time reader.
I’m sure this is trivial, but I’m new to scripting! Any pointers would be appreciated.
sortingThroughIndexes.gh (11.1 KB)
I’ve written this c# script to sort through the indexes of intersecting lines and place them in separate branches. I’m trying to group the lines based on their connectivity. They don’t intersect and their endpoints frustratingly. The script should traverse through the two index lists to build a final list, then output a branch of corresponding curves.
I’m getting two errors, either
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index (line: 0)
or
Array dimensions exceeded supported range. (line: 0)
private void RunScript(List<int> a, List<int> b, List<Curve> curves, int startCurveCount, ref object A)
{
DataTree<Curve> curveTree = new DataTree<Curve>(); // Create a new tree
for (int i = 0; i < startCurveCount; i++) //for each starting curve
{
List<int> indexList = new List<int>(); //create a new list
int currentIndex = a[i]; //start at the first index
while (currentIndex >= 0 && currentIndex < curves.Count) //whilst the index is less than the total curve count
{
indexList.Add(currentIndex); //add the index to the list
currentIndex = a[currentIndex]; //increment the currentIndex by the value in list a
if (currentIndex >= 0 && currentIndex < curves.Count) //check that the index is still less than the total count
{
indexList.Add(currentIndex); //add the index to the list
currentIndex = b[currentIndex]; //increment the currentIndex by its value in list b
}
}
// Convert the index list to a path and add curves to the tree
GH_Path path = new GH_Path(i);
foreach (int index in indexList)
{
curveTree.Add(curves[index], path); //add all the curves that correspond to the indexList to path i
}
}
A = curveTree; // output the tree of curves
}
Let me know if there’s a better way to do this, or if I haven’t explained well! I might be barking up the wrong tree.
Many thanks in advance