I'm not sure if this is possible but I've been trying to get the AREA_SCHEME_NAME from a collection of areas. I've tried several ways without luck. Can an area report what Area Scheme (Gross, Rentable) it belongs to?
IList<SpatialElement> areas = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Areas)
.OfClass(typeof(SpatialElement))
.Cast<SpatialElement>()
.ToList();
foreach (Element e in areas)
{ e.get_Parameter...
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
Dear Derek,
Thank you for your query.
I am checking with the development team for you.
On a side note, your code sample above is unnecessarily inefficient.
No need for the cast, and more importantly, ToList adds no value for this use case and consumes both time and memory:
I'll let you know what I hear back from the development team on your main question.
Best regards,
Jeremy
Have you tried this?
Area _area ; AreaScheme _scheme = document.GetElement(_area.get_Parameter(BuiltInParameter.AREA_SCHEME_ID).AsElementId()) as AreaScheme; string _AreaSchemeName = _scheme.get_Parameter(BuiltInParameter.AREA_SCHEME_NAME).AsString();
IList<SpatialElement> areas = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_Areas) .OfClass(typeof(SpatialElement)) .Cast<SpatialElement>() .ToList(); foreach(Element e in areas) { AreaScheme _scheme = doc.GetElement(e.get_Parameter(BuiltInParameter.AREA_SCHEME_ID).AsElementId()) as AreaScheme; string _AreaSchemeName = _scheme.get_Parameter(BuiltInParameter.AREA_SCHEME_NAME).AsString(); if (_AreaSchemeName.ToString() == "Gross Building") { TaskDialog.Show("Revit", _AreaSchemeName); double ox = e.LookupParameter("Area").AsDouble(); TaskDialog.Show("Revit", ox.ToString()); } else { continue; } }
Thanks FAIR59. Here's the code for a little test to get the areas that are on the 'Gross Building' scheme.
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
Summarised and published on the blog:
Thank you!
Cheers,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.