Loop through your elements looking for a level type, and when you find one use the level.ProjectElevation property to get its height - in decimal feet of course. At first I added these up to get total height, but then realised that ProjectElevation returns the elevation of the level relative to the project origin, so all we want is the highest figure we can find of all our levels.
Dim elementIterator As Autodesk.Revit.ElementIterator elementIterator = revitApp.ActiveDocument.Elements Dim height As Double While (elementIterator.MoveNext()) 'look for level types If TypeOf elementIterator.Current Is Autodesk.Revit.Elements.Level Then Dim level As Elements.Level = elementIterator.Current 'is current value higher than previous values? If level.ProjectElevation > height Then height = level.ProjectElevation End If End If End While MessageBox.Show("Height: " & height)
UPDATE: This only retrieves the elevation of the uppermost level, which isn't the height of the building - see my next post for a different approach!
Hi Ed,
ReplyDeleteA better way to select all levels is to use the selection filters (2008+).
Dim TypeFilter As Autodesk.Revit.Filter = MyApp.Create.Filter.NewTypeFilter(GetType(Autodesk.Revit.Elements.Level))
Dim CatFilter As Autodesk.Revit.Filter = MyApp.Create.Filter.NewCategoryFilter(Autodesk.Revit.BuiltInCategory.OST_Levels)
Dim LvlFilter As Autodesk.Revit.Filter = MyApp.Create.Filter.NewLogicAndFilter(CatFilter, TypeFilter)
Dim result As New List(Of Autodesk.Revit.Element)
Dim NumLevels As Integer = MyDoc.Elements(LvlFilter, result)
Thanks Krispy5, it's my old skool habits that I keep slipping into - quick and dirty coding :)
ReplyDeleteType filters are definitely more elegant!
Hmmm I've just realised this doesn't give the height of the building - it gives me the elevation of the uppermost level - i.e. the level at which it is placed.
ReplyDeleteI'll hopefully find some time today to add the extra bit on! :)
Krispy5, in your suggestion you're using both a type and category (with built-in category OST_Levels) filter to get your levels. Is this just a belt-and-braces approach you always use? The type filter alone does the job in my tests.
ReplyDeleteCould a level type ever be found in a different category? I'd be interested to know if I should be using more category filters like this.
I remember that one or the other would also return the types of level as well as the actual instances of levels, so i usually use this method as a "catch all"
ReplyDelete