Remember in the last post, where we discussed about how we retrieve the summed length of curve elements? After that post, we had a similar one, where the summed value is the retrieved area of room instead of length? And we also had a improved function, with which the report of value is determined automatically according to the current project unit.

Now, in this post, we are also going to do some improvement, by using some of the convenient F# functions. We are going to retrieve the summed length of linear elements, such as, in this example, we combined the length of curve elements, wall and structural framing elements.

As here demonstrated, it is quite similar to the code for the summed length of curve elements. However, it is different at the part, determining which kind of elements are supposed to be selected (line 14). In this step, we use, instead of the “filter“, we use the “map” function of Seq. This function maps the elements to their representative curves according to our chosen types: If the element is, of the first and second types, i.e. of Curve Element or Wall types (line 16, 17), the function returns a “Some“, an F# Option instance, with a value of Curve, which is retrieved from the element’s GeometryCurve or LocationCurve properties, respectively. Or it is of the third type, StructuralFraming, which is being determined by, firstly, if the element is a FamilyInstance, then, secondly, if its category is StructuralFraming. Finally in this mapping function, since F# is a “type safe” language, if none of these three types is matched, we still have to have the same type as Some returned, the function will return another Option instance: None. In the following selection process, we can then filter out what we want – the curves, which have the length of the linear elements, by using “Seq.filter” on the option objects, if its “IsSome” property is true.

Until this point, this code is almost completed, except that the filtered and selected elements are not curves yet. They are still “packed” in the Some instance of the Option type. But to get them is just simply by calling the Value property of Some, and the Length is directly an property of this Value, i.e. the Curve (line 35).