Home Ask Login Register

Developers Planet

Your answer is one click away!

Thijser February 2016

Gettings information about stairsruns and stairs from elements containing such information

Hello I have the following code:

   public static void HandleStairs(Document doc)
        List<TransitionPoint> ret = new List<TransitionPoint>();
        FilteredElementCollector collector = new FilteredElementCollector(doc);
        ICollection<Element> stairs = collector.OfCategory(BuiltInCategory.OST_Stairs).ToElements();
            foreach (var stair in stairs)
                 var st= stair as Stairs;
                        %code that is never executed

        return ret;

Now the problem is that no matter what it appears stairs are always null, I heard that another programmer had the same problem.

the stairs variable does receive a number of object with stairlike properties (being named staircase, having risers and platforms ext.) but does not actually appear to accept being cast to a stair. Anybody know how to actually cast this into stairs (or otherwise obtain all stairs in an document?)

Note that stairs is an element with the following properties:

Riser to Tread Connection
Monolithic Material
Apply Nosing Profile
Stringer Material
Text Size
Begin with Riser
Stringer Carriage Height
Open Stringer Offset
Right Stringer
Riser Type
Left Stringer
Underside of Winder
Stringer Height
Nosing Profile
Middle Stringers
Riser Material
Minimum Tread Depth
Text Font
Monolithic Stairs
Maximum Riser Height
Landing Carriage Height
Break Symbol in Plan
Landing Overlap
Extend Below Base
Nosing Length
Assembly Description
End with Riser
Type Image
Type Comments
Stringer Thickness
Assembly Code
Calculation Rules
Trim Stringers at Top
Tread Thickness
Tread Material
Riser Thickness

I mostly need the stair objects to get the runs assosiated with the stair objects, or actually I need the paths the runs follow.


Mark February 2016

The as operator returns null if the cast fails, so whatever doc.GetElement(stairId) returns is not of type Stairs or one of its sub-types.

I'm guessing doc is some kind of 'storage' document so you probably need to create a new instance of Stairs and fill it with information you get from whatever doc.GetElement(stairId) returns.

Jeremy Tammik February 2016

First of all, you absolutely have to find out and tell us what kind of element you are talking about. Otherwise, this discussion is completely pointless. One very easy way to determine that is to explore the 'stair-like' element using RevitLookup:


If you do not know what RevitLookup is, you should stop absolutely everything else you are doing with the Revit API right away and start off fresh by working through the Revit API getting started material, especially installing and starting to use RevitLookup:


The filtered element collector you show retrieves all elements of the 'Stairs' category. This 'stair-like object' could be a DirectShape, in which case you can assign it the 'Stairs' category. Then it will be retrieved by your filtered element collector above.

Here is an example of a 'stair-like' extruded roof, which is and will always remain a roof, with the 'Roofs' category, and thus can never be identified by your filtered element collector:


Sorry for the confusing answer, but I must say your question is pretty confusing too. Never heard anything like it before. I hope this helps.

Matt February 2016

What you've done looks reasonable, although as others have pointed out, obviously somehow you are getting back an element which is not a Stair element.

I would suggest - in order to make sure you get back what you want, that you use:


with the FilteredElementCollector. With this, you can probably drop the WhereElementIsNotElementType() and OfCategory() methods, because it is implicit in the above statement.

This way - whatever you get back should be cast-able.

Post Status

Asked in February 2016
Viewed 1,853 times
Voted 7
Answered 3 times


Leave an answer

Quote of the day: live life