Say you have 8 points (conveniently the number which make up a cube), as follows:
Point.ByCoordinates(
[0,10,10,0,0,10,10,0],
[0,0,10,10,0,0,10,10],
[0,0,0,0,10,10,10,10]
);
Looks like this:
And you want to play connect the dots to build a cube (told you the count was convenient). You can obviously connect index 0 and 1 by pulling every Nth item (so just index 0 and 1), or you could use what I showed above:
pnts = lst[0..1]
This gets the first and second (index 0 and 1) out of the list. And so we can draw a line connecting the two points thusly:
This is taking the list item (defined as lst - an input into the code block) and getting the items at each index in the list of indexes which I defined by the design script syntax for range: 0…1.
But the connections for our points are much more complex; fortunately we can define a list of lists of indexes like this
lst [ listOfIndexPairs ];
Then we can define the listOfIndexPairs by manually typing it up (for now), and we get something like this:
But typing those pairs… well it stinks - doubly so if the counts vary. So let’s look at defining them programmatically by building a range of indexes and pulling the pairs you want with list manipulation.
//the original list of points
lst =
Point.ByCoordinates(
[0,10,10,0,0,10,10,0],
[0,0,10,10,0,0,10,10],
[0,0,0,0,10,10,10,10]
);
//get the number of items
count = List.Count(lst);
//build the range of index numbers
range = 0..count-1;
//get the first half of the index numbers
low = range[0..#count/2..1];
//shift the low index numbers by -1
lowShift = List.ShiftIndices(low,-1);
//get the second half of the points by adding 1/2 of the count to the low value
high = low+count/2;
//get the second half of the points by adding 1/2 of the count to the low value
highShift = List.ShiftIndices(high,-1);
//build the pairs by transposing the sets
listOfIndexPairs =
List.Join(
[
List.Transpose( [low, lowShift] ),
List.Transpose( [high, highShift] ),
List.Transpose( [low, high] )
]
);
lst[ listOfIndexPairs ];
Looks like this:
And as a result you can even do really crazy stuff when you don’t know the counts, but know the relationships. For example you can do this:
Hope this helps clear stuff up!