Hi All,
If I have an expression that contains a list of polygons, is there any way I can select every second value from that expression? In the script I am working on I have an expression that contains all the polygons that represent the start and end of a concrete barrier (I am modelling pre-cast concrete barriers with gaps between them). I want to create a BSplineSurface from the polygons using "Ruled" where the even polygons are the "StartCurve" inputs and the odd polygons are the "EndCurve" inputs (so I end up with individual BSplineSurfaces for each barrier with a gap between them). At the moment the only way I can get this to work is by typing the information into the expressions for the StartCurve and EndCurve separately.
Regards,
Ryan
Hi Ryan,
If you are using u7 you might be able to use the "Operator" node to achieve this, but it is simple enough to create a function if your list has a depth of 1 (no nested lists):
The function:
function(object input) { int output = {}; //create an output array int j = 0; //create a new starting index for the output array for(int i = 0; i < input.Count; ++i) //iterate through the input object { if(i % 2 != 0) //if the index number is odd { output[j] = input[i]; //return the value at that index ++j; //next index } } return output; }
In your case you would want to change the type of the output variable to be a polygon instead of int. If you haven't seen a modulus operator before, it is represented by a "%" symbol and is used to determine the amount left over if you divide by 'x'; in this case we determine if i / 2 does not leave a remainder of 0, then it is an odd number.
Cheers,Ed
Answer Verified By: Ryan McCormack
Thanks Ed,
That does exactly what I wanted.
Much appreciated.