Dear Frank and Derek,
Thank you very much for the simple solution!
I refactored Frank's code as a separate little method to retrieve the area scheme name from the area element like this:
/// <summary>
/// Return the area scheme name of a given area element
/// using only generic Element Parameter access.
/// </summary>
static string GetAreaSchemeNameFromArea( Element e )
{
if( !(e is Area) )
{
throw new ArgumentException(
"Expected Area element input argument." );
}
Document doc = e.Document;
Parameter p = e.get_Parameter(
BuiltInParameter.AREA_SCHEME_ID );
if(null==p)
{
throw new ArgumentException(
"element lacks AREA_SCHEME_ID parameter" );
}
Element areaScheme = doc.GetElement( p.AsElementId() );
p = areaScheme.get_Parameter(
BuiltInParameter.AREA_SCHEME_NAME );
if( null == p )
{
throw new ArgumentException(
"area scheme lacks AREA_SCHEME_NAME parameter" );
}
return p.AsString();
}
With that in hand, the retrieval of all areas matching a given area scheme can we rewritten like this:
/// <summary>
/// Retrieve all areas belonging to
/// a specific area scheme.
/// </summary>
public IEnumerable<Element> GetAreasInAreaScheme(
Document doc,
string areaSchemeName )
{
return new FilteredElementCollector( doc )
.OfCategory( BuiltInCategory.OST_Areas )
.OfClass( typeof( SpatialElement ) )
.Where<Element>( e => areaSchemeName.Equals(
GetAreaSchemeNameFromArea( e ) ) );
}
I added these two methods to The Building Coder samples release 2017.0.132.10:
https://github.com/jeremytammik/the_building_coder_samples
https://github.com/jeremytammik/the_building_coder_samples/releases/tag/2017.0.132.10
You can see the new code by comparing with the preceding release 2017.0.132.9:
https://github.com/jeremytammik/the_building_coder_samples/compare/2017.0.132.9...2017.0.132.10
It would be really nice if you would like to try out these two methods and confirm that they work as expected.
Thank you!
Cheers,
Jeremy