Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Area Scheme from an Area

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
dkam47
2133 Views, 6 Replies

Get Area Scheme from an Area

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

Tags (2)
6 REPLIES 6
Message 2 of 7
jeremytammik
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

Message 3 of 7
dkam47
in reply to: jeremytammik

Jeremy,

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

 

Derek

Message 4 of 7
FAIR59
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();
Message 5 of 7
dkam47
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.

Message 6 of 7
jeremytammik
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

Message 7 of 7
jeremytammik
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community