Dear Bernie,
Thank you for your query, and many thanks to Recep for his valuable help.
His suggestion can be improved upon.
Calling ToList at the end is a waste of time and space.
It requests a (totally unnecessary) copy of all the results from the filtered element collector.
You can iterate over the collector itself directly.
Furthermore, a built-in Revit filter will always be faster than LINQ post-processing.
In this case, you can use a negated ElementCategoryFilter:
https://apidocs.co/apps/revit/2019/6b8f4e3a-1975-7388-3848-462cf305d523.htm
Yet further, you might gain some additional performance by deleting all the elements in one single call rather than by stepping through them one by one.
For instance, like this:
/// <summary>
/// Delete all non-room-separating curve elements
/// </summary>
void DeleteNonRoomSeparators( Document doc )
{
ElementCategoryFilter non_room_separator
= new ElementCategoryFilter(
BuiltInCategory.OST_RoomSeparationLines,
true );
FilteredElementCollector a
= new FilteredElementCollector( doc )
.OfClass( typeof( CurveElement ) )
.WherePasses( non_room_separator );
doc.Delete( a.ToElementIds() );
}
I added this method to The Building Coder samples for you:
https://github.com/jeremytammik/the_building_coder_samples/compare/2020.0.145.2...2020.0.145.3
I hope this helps.
Best regards,
Jeremy