Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.

Revit API Forum

Reply
Highlighted
Post 1 of 7
Accepted Solution

Get Area Scheme from an Area

71 Views, 6 Replies
03-15-2017 04:44 PM

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...

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();
Post 2 of 7

Re: Get Area Scheme from an Area

03-16-2017 03:11 AM in reply to: dkam47

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Post 3 of 7

Re: Get Area Scheme from an Area

03-16-2017 09:09 AM in reply to: jeremytammik

Jeremy,

Thank you for looking into this and thanks for the links.

 

Derek

Post 4 of 7

Re: Get Area Scheme from an Area

03-16-2017 03:31 PM in reply to: dkam47

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();
Post 5 of 7

Re: Get Area Scheme from an Area

03-16-2017 04:50 PM in reply to: FAIR59
            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.

Post 6 of 7

Re: Get Area Scheme from an Area

03-17-2017 01:41 AM in reply to: dkam47

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Post 7 of 7

Re: Get Area Scheme from an Area

03-17-2017 04:53 AM in reply to: jeremytammik

Summarised and published on the blog:

 

http://thebuildingcoder.typepad.com/blog/2017/03/q4r4-first-queries-revitlookup-and-areas-in-schemes...

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post

Revit Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Revit helps you achieve greater speed, accuracy, and automation from concept to manufacturing.