Get Area Type value C#

Hi Guys,
I am trying to get access to the value of the Area Type parameter the Area Element : Building Common Area, Office Area … etc But I cant seem to be able to find how to access these values, and by the look of it in the Revit interface I guess they must be defined as an enum structure somewhere in the API

Capture

but it seems that its hidden in the deepest pits of hell!! lol

here is my code:

  public List<string> Foo(Document doc)
        {
            IEnumerable<Area> areas = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfClass(typeof(SpatialElement))
              .Where(e => e.GetType() == typeof(Area))
              .Cast<Area>(); ;

            List<string> output = new List<string>();
            foreach (var area in areas)
            {
                Parameter areaType = area.get_Parameter(BuiltInParameter.AREA_TYPE);      

                //output.Add(areaType.ToString());  gives: Autodesk.Revit.DB.Paramater 

                Definition def = areaType.Definition;
               
               // output.Add(def.Name); // gives: Area Type

                output.Add(areaType.AsString()); // gives: nothing  I guess it because it does not have a string representation


            }

            return output;
        }

The closest I have gotten is through Definition def = areaType.Definition; and then accessing def.Name property, which will give a string equal to Area Type.

Any hints would be awesome!

1 Like

hi,

if i understood you correctly there are actually two parameters that can give you the value:

-from AREA_TYPE you have to use AsValueString() instead of AsString()
-from AREA_TYPE_TEXT AsString() works (probably it has string as a storage value…i havn’t checked)

AsValueString() is used for parameters that have other storage types than string…it gives the human readable representation of doubles, integers etc.

2 Likes

Hi again @maciek.glowka

Both versions worked! its very interesting to see how different the Revit API in terms of design is from the RhinoCommon API, Revit seems to be much more of a maze and harder to get at things.

Anyways, thanks for the reply, I guess we will encounter again here in the developer forum.

1 Like

Wanted to throw the Revit Lookup tool out there for other devs to use.

It is a must have and a signed installer is available through boost your bim.

and the github for the project

1 Like

@john_pierson yes I did use it, but I still could not find the correct path to my question, thanks anyways

:+1:

yeah…also working with directly with Revit itself (UI) is not exactly consistent and logical…I often wonder whether Autodesk will ever make a decision to rewrite Revit from scratch…there seems to be a lot of history in the code…

1 Like